1function doRequest(url) {
2 return new Promise(function (resolve, reject) {
3 request(url, function (error, res, body) {
4 if (!error && res.statusCode == 200) {
5 resolve(body);
6 } else {
7 reject(error);
8 }
9 });
10 });
11}
12
13// Usage:
14
15async function main() {
16 let res = await doRequest(url);
17 console.log(res);
18}
19
20main();
1app.post('/signup', async(req, res) => {
2 try {
3 const { email, firstName } = req.body
4 const user = new User({ email, firstName })
5 const ret = await user.save()
6 res.json(ret)
7 } catch (error) {
8 console.log(error)
9 }
10})
11
1app.post('/signup', async(req, res, next) => {
2 async function runAsync () {
3 await firstThing()
4 await secondThing()
5 }
6
7 runAsync()
8 .catch(next)
9})
10