티스토리 뷰
Example code
app.post("/register", (req, res) => {
User.findOne({username: req.body.username}, async(err, doc) => {
if(err) throw err;
if(doc) res.send('User already exist');
if(!doc){
const hashedPassword = await bcrypt.hash(req.body.password, 10);
const newUser = new User({
username: req.body.username,
password: hashedPassword,
});
await newUser.save();
res.send('User Created')
}
})
})
bcrypt 가 promise를 return하기에 async/await을 붙여야 error가 나지 않는다.
난 await을 빼먹어서 계속 에러가 났던 것...
Reference
stackoverflow.com/questions/48799894/trying-to-hash-a-password-using-bcrypt-inside-an-async-function
Trying to hash a password using bcrypt inside an async function
Following on from this question. I feel like I'm almost there, but my incomplete understanding of async is preventing me from solving this. I'm basically trying to just hash a password using bcryp...
stackoverflow.com
medium.com/dev-bits/writing-neat-asynchronous-node-js-code-with-promises-32ed3a4fd098
Writing neat asynchronous Node JS code with Promises
Write beautiful code with JavaScript Promises
medium.com
'Node.js' 카테고리의 다른 글
Upgrade node.js version (0) | 2021.01.23 |
---|---|
Module in Node.js (0) | 2019.09.04 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 알고리즘
- ... in Javascript
- hackerrank javascript solution
- compareTo()
- easy algorithm
- Object type casting
- hackerrank solution
- Javascript Algorithm
- hackerrank
- easy javascript algorithm
- Collection Framework
- string class in java
- math.max
- 프로그래머스
- repeat()
- HackerRank Algorithm
- 프로그래머스 알고리즘문제
- C++
- code refactoring
- hackerrank javascript
- rest parameter
- 프로그래머스 알고리즘
- algorithm
- substring()
- spring boot application
- equals()
- javascript
- java
- math.abs
- HashMap
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함