I had learned 2 MEAN courses (MongoDB, Express, Angular, Node.js) which creates a simple blog and in the both courses next() method is never used.
Is it OK? Both projects work properly.
Do I have to write code further without next() method or I have to start use it?
I have read that without 'return next()' a function can be called twice or something like that.
Please, advise.
router.post('/dashboard', passport.authenticate('jwt', { session: false }),
(req, res) => {
try {
let newPost = new Post({
category: req.body.category,
title: req.body.title,
photo: req.body.photo,
text: req.body.text,
author: req.body.author,
date: req.body.date
});
Post.addPost(newPost, (err, user) => {
if (err) {
res.json({success: false, msg: `Post has not been added. ${err}`})
} else {
res.json({success: true, msg: 'Post was added.'})
}
})
} catch (err) {
const error = (res, error) => {
res.status(500).json({
success: false,
message: error.message ? error.message : error
})
}
console.log('error routes/auth POST', res, error)
}
})