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
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.