I've got a node.js app hosted on Heroku
Whenever my app encounters an error, the whole server crashes, making it unavailable for anyone.
Is there any way to return an error page instead, and keep the server alive?
I read this, Node.JS with forever on Heroku but it didn't answer my question....
Initially, it supported only Ruby sites but now supports various languages, including JavaScript with Node. js. Heroku also has Docker support so that you can deploy just about anything to it. This tutorial will teach you how to build a small application using the Express framework for Node.
http://nodejs.org/docs/latest/api/process.html#process_event_uncaughtexception
You can listen for the uncaughtException event and then do your error handling. Ideally, your callbacks should return an err argument and then do the error handling.
You can probably use DOMAIN, this will probably stop your server from crashing when an uncaughtException is thrown.
domain = require('domain'),
d = domain.create();
d.on('error', function(err) {
console.error(err);
});
for more details go http://shapeshed.com/uncaught-exceptions-in-node/
beside using this method must try-catch your block.
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