Answers for "expressjs async await"

3

node js request 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();
Posted by: Guest on May-23-2020
1

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)
  }
})
Posted by: Guest on January-28-2021
0

expressjs4 async

app.post('/signup', async(req, res, next) => {
  async function runAsync () {
    await firstThing()
    await secondThing()
  }

  runAsync()
    .catch(next)
})
Posted by: Guest on September-17-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language