I am writing a controller that creates a user account. I wanted to do it using async/await but I have no idea how to save the object to db without using promises or callbacks.exports.signup_post = async (req, res, next) => { try { let hashedPassword = await bcrypt.hash(req.body.password, salt); let user = await new adminuser({ username: req.body.username, password: hashedPassword }).save() .then(it => { res.redirect("/"); }) .catch(err => { res.redirect("/cm"); }); } catch (err) { res.redirect("/cms"); } }; By the way, I am just starting to learn node/express, if you have any protips I would be glad to hear them.
Submitted February 01, 2020 at 02:27AM by radekpies
No comments:
Post a Comment