
- async
node는 기본적으로 비동기 처리를 한다.
콜백지옥을 해결하기 위해서 async/await, promise, async 모듈이 있다
이중 async 모듈을 보겠다
async 모듈은 동기방식으로 쉽게 바꿔준다.
설치
npm install async --save
- async waterfall
코드를 순차적으로 실행
function myFirstFunction(callback) {
callback(null, ['one'], ['two']);
}
function mySecondFunction(arg1, arg2, callback) {
// arg1 now equals 'one' and arg2 now equals 'two'
callback(null, ['three']);
}
function myLastFunction(arg1, callback) {
// arg1 now equals 'three'
callback(null, ['done']);
}
var tasks = [
myFirstFunction,
mySecondFunction,
myLastFunction
];
async.waterfall(tasks, function (err, result) {
if (err) {
console.log("에러 :", err.message);
} else {
console.log("완료 :", result);
}
});
'Programing > node js' 카테고리의 다른 글
| node js pm2 (0) | 2021.02.23 |
|---|---|
| node js mysql session 사용법 (0) | 2021.02.19 |
| node js panolens.js 360이미지 (0) | 2021.01.14 |
| node js 네이버 계정으로 로그인 (passport-naver) (0) | 2021.01.12 |
| node js mysql 연동 암호화 로그인 (0) | 2021.01.11 |