I am new to javascript and node and trying to create an application using node.js and express.
I set the appropriate callbacks for errors, but they do not fit everywhere, and sometimes the node.js server just stops due to some kind of exception that comes up.
It is recommended to use “upstart” or “forever” to always support node.js and start it, whether node.js stops.
Express seems to provide the trick for all exceptions at http://expressjs.com/guide.html#error-handling
app.use(function(err, req, res, next){
console.error(err.stack);
res.send(500, 'Something broke!');
});
Now it works for me. However, I read somewhere that a trap like this is not a good idea, since it can have side effects and can leave variables in an inconsistent state? In addition, an exception like this does not work for all cases, and there may be some cases where the server can still stop for some exception. It's true?
My questions are probably this.
1) Can exception handling, as above, leave some variables in an inconsistent state? 2) Can there be some exceptions that will stop the server anyway?
Thanks and Regards
Tuco
source
share