Handling or prevent errors from crashing my whole node.js app on Heroku

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....

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.