Question

according to many articles, the best way to handle uncaught exceptions in a node.js app is let the process crash and than restart it. This avoids to have our application in a unstable state. I think it can be done with an external process like a watchdog (sometimes called angel process). What is the best way to do this in a linux system? At first glance a bash script checking the node process state every n seconds could be a possible solution. Thank in advance, any suggestion will be really appreciated.

Node.js Best Practice Exception Handling

http://shapeshed.com/uncaught-exceptions-in-node/

http://debuggable.com/posts/node-js-dealing-with-uncaught-exceptions:4c933d54-1428-443c-928d-4e1ecbdd56cb

Was it helpful?

Solution

There are a handful of solutions like the watchdog/angel process you mention. The one you most often hear thrown around is "forever". It's available via npm.

To install, just: npm install -g forever

Then when you want to run your app: forever app.js instead of node app.js

OTHER TIPS

I have successfully used supervisord, I think it fits your purpose very well. It's not node-specific and you can use it virtually with anything that won't detach from the console.

And with the events feature, it gives a nice flexible tool for all kinds of scenarios.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top