My code was working just fine, but out of no where I started getting this error. ReferenceError: next is not defined. No clue how I started getting it as I didn't change this function at all.
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');
});
};
next
is the 3rd parameter to any middleware. So the code should be:
exports.addAccount = (req, res, next) => {
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.