Search code examples
linuxnode.jsuncaught-exception

Node.js uncaught exceptions


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


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