Is there any alternative to PHP error_reporting(0) in nodejs? I want to prevent app from closing after an error, I tried the try and catch method, but it doesn't work.
So, how can I prevent node.js server from closing after an error ?
Edit: There is an event for uncaught errors:
process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err);
});
See duplicate: Make node.js not exit on error
You could also use pm2 to run your script, pm2 will automatically restart your script on crash.
You need to catch the error. For example
try {
error();
} catch(err) {
// do nothing
}
There is no other way as far as i know. So you could fix or catch these errors only.
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