Saturday, 1 February 2020

Should one always have callbacks for handling errors?

Why do node.js / express.js tutorials teach to write code this way:function addModel(cms) { var nmain = new cms({ lineeng: req.body.lineeng, linepl: req.body.linepl }); nmain.save((err) => { if (err) { return next(err); } res.redirect('/cms'); }); } Whre you could write justfunction addModel(cms) { var nmain = new cms({ lineeng: req.body.lineeng, linepl: req.body.linepl }); nmain.save(); res.redirect('/cms'); } And have it do exactly the same? Is error handling always required?

Submitted February 02, 2020 at 02:34AM by radekpies

No comments:

Post a Comment