简体   繁体   中英

Managing runtime errors in node.js

I'm wondering what approach people are using to keep node.js instances running, in the face of runtime errors.

Uncaught runtime exceptions will take the node process down (effectively taking down your server). I think people often mitigate this with tools like forever or upstart, which will just bring the process back up again if it crashes. This seems fine for simple web server scenarios, but if you're maintaining a session eg over websockets, then this is not really a solution (as it drops all of your sessions).

Of course, ideally I should be catching potential exceptions, but something is always going to be missed.

So, what solutions are there?

You can use process.uncaughtException event to handle uncaught exeptions without application restart.

In node 0.8.x you can use domain module to handle errors smarter. For express/connect you can use connect-domain module.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM