expressjs async await
function doRequest(url) {
return new Promise(function (resolve, reject) {
request(url, function (error, res, body) {
if (!error && res.statusCode == 200) {
resolve(body);
} else {
reject(error);
}
});
});
}
// Usage:
async function main() {
let res = await doRequest(url);
console.log(res);
}
main();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)
}
})
app.post('/signup', async(req, res, next) => {
async function runAsync () {
await firstThing()
await secondThing()
}
runAsync()
.catch(next)
})
Also in JavaScript:
- javascript strip
- chartjs how to disable hover lable
- foreach and replace item based on condition
- advanced axios in react js using create and interceptor
- data type angular
- how to check if 2 images are touching js
- javascript training
- js get copied text
- canvas set background color
- 404 json laravel
- angular themeable components
- how to javascript
- heroku node js h21 backend connection refused
- capitalize first letter of each word javascript
- react live chat widget
- jquery select specific radio button by value
- javascript set color in hex
- node js mysql starter github
- Javascript format to currency
- funcion dentro de objeto
- javascript get elements that exist in two arrays
- You are running Node 8.10.0. Create React App requires Node 10 or higher. Please update your version of Node.
- javascript project ideas
- jquery cheat sheet