Airbrake and Forever to keep you happy

When developing with Node.js, you’ll notice that, unlike in PHP, if you encounter a really nasty unhandled exception or error, the entire application crashes, instead of just that particular request. While that can be helpful during development, it isn’t ideal to show the Heroku error page to your users in production.

Airbrake (formerly HopToad) is available as a Heroku add-on, and along with the node-airbrake module (thanks felixge!), sending yourself emails with a stack trace when the server crashes is stupid easy.

While that makes your response time to crashes much better, it doesn’t do anything to keep your server available until you manually restart the Heroku process. That’s where Forever comes in, an excellent module from Nodejitsu that will automatically restart your server when it goes down.

Obviously restarting your borked server over and over isn’t a permanent solution, but it allows your server to stay available for the rest of your users even if one of them finds an obscure bug, and gives you a bit more time to find the source of the issue.

Just add a file (mine’s called forever.js) that starts your server with forever, and notifies Airbrake when the server is actually down.

That should let you sleep a little bit easier!