Keep NodeJS Alive With Uncaught Exception


odeJS is still a pretty young project, and as you might expect, things can sometimes go wrong with out any obvious reason as to why. The [http module]( for example, especially in some earlier versions of node, will just throw an error and die - bringing your application down with out batting an eye! While not the most desireable method, you can pretty much catch any error comming from a NodeJS process and react accordingly:

process.on( "uncaughtException", function( err ){
    //do something usefull
	console.log( err )

NodeJS exposes a global object called process that you can listen for the uncaughtException event oddly enough, which you can listen to. As long as your handlers do not throw errors, your Node app will continue to run as usual. You would obviously want to do something a little more useful here like logging your error somewhere they could be viewed for debugging purposes, etc. But, That is really all there is to it!

exceptions http durability node.js