express async await code example
Example 1: async await
const data = async () => {
const got = await fetch('https://jsonplaceholder.typicode.com/todos/1');
console.log(await got.json())
}
data();
Example 2: expressjs async await
app.post('/signup', async(req, res) => {
try {
const { email, firstName } = req.body
const user = new User({ email, firstName })
const ret = await user.save()
res.json(ret)
} catch (error) {
console.log(error)
}
})
Example 3: async await
async function showAvatar() {
await setTimeout(resolve, 3000);
}
showAvatar();