ther by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). to terminate the node process on unhandled promise rejection, use the cli flag --unhandled-rejections=strict (see [
const router = require("express").Router();
const User = require("../modles/User");
router.get("/register", async (req,res) => {
const user = await new User({
username:"jhon",
email:"jhon@gmail.com",
password:"123456",
})
await user.save()
res.send("ok")
});
module.exports = router;
]1 (rejection id: 1) (node:13400) [dep0018] deprecationwarning: unhandled promise rejections are deprecated. in the future, promise rejections that are not handled will terminate the node.js process with a non-zero exit code.
you only need a await and a catch. The first one is useless because you initialize your class.
So do that :
const router = require("express").Router();
const User = require("../modles/User");
router.get("/register", async (req,res) => {
const user = new User({
username:"jhon",
email:"jhon@gmail.com",
password:"123456",
})
await user.save().catch(e => e) // Return the errors in the void. You can console.log it.
res.send("ok")
});
module.exports = router;