My node.js (Express.js) application crashes every time an error occurs (syntax, undefined variable, etc.).
Is there any solution to just log it and not crash my app? I read node.js Error's documentation but can't find a solution. https://nodejs.org/api/errors.html
I generated application from express generator. I'm talking about this, here is syntax error, variable is undefined but server is running: http://prnt.sc/e2b7ce it's not crashed
You could catch the error, but you should not do this with errors that are your fault, because it is in an unpredictible state after such an error its the best to restart the whole app (nodemon, forever). Errors like not reaching the db, validation, errors in promises, ... you should catch it.
To your second question, you can use the event for unhandled errors like that
process.on('uncaughtException', err => {})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With