我有以下代码将新条目保存在数据库Mongo中,我想通过nodemailer发送电子邮件,以防成功“ res.status(201)”。我的代码应该放在哪里?
register: (req, res, next) => {
bcrypt.hash(req.body.password, 10)
.then(hash => {
const person= new Person({
email: req.body.email,
password: hash
});
person.save()
.then(() => res.status(201).json({ message: "OK" }))
.catch((error) => res.status(400).json({ message: error }))
})
.catch(error => res.status(500).json({ message: error }));
},
感谢您的帮助
解决方案是:
register: (req, res, next) => {
bcrypt.hash(req.body.password, 10)
.then(hash => {
const person= new Person({
email: req.body.email,
password: hash
});
person.save()
.then(() =>
{
res.status(201).json({ message: "OK" }))
... nodemailer here ...
}
.catch((error) => res.status(400).json({ message: error }))
})
.catch(error => res.status(500).json({ message: error }));
},