我的代码工作正常,但是我从哪里开始出现此错误。 ReferenceError:下一个未定义。 不知道如何开始获取它,因为我根本没有更改此功能。
const Accounts = require('../data/accounts.model')
exports.addAccount = (req, res) => {
const newAccount = new Accounts({
Username: req.body.Username,
Password: req.body.Password,
AccountType: req.body.AccountType,
Email: req.body.Email,
Age: req.body.Age,
Question1A: req.body.Question1A,
Question2A: req.body.Question2A,
Question3A: req.body.Question3A,
});
newAccount.save((err) => {
if (err){
return next(err);
//error happens here^
}
res.send('Account created Successfully');
});
};
答案 0 :(得分:1)
next
是任何中间件的第三个参数。因此代码应为:
exports.addAccount = (req, res, next) => {