Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

mongoose await save

try {
  const newUser = new User({
    'email': req.body.email,
    'name': req.body.name
  });
  console.log('before save');
  let saveUser = await newUser.save(); //when fail its goes to catch
  console.log(saveUser); //when success it print.
  console.log('after save');
} catch (err) {
  console.log('err' + err);
  res.status(500).send(err);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #mongoose #await #save
ADD COMMENT
Topic
Name
2+8 =