如何提高NodeJS程序的运行的稳定性

如何提高NodeJS程序运行的稳定性

 

我们常通过node app.js方式运行nodejs程序,但总有一些异常或错误导致程序运行停止退出。如何保证node程序的稳定运行?

下面是一些可以考虑的方案:

1.使用最新的node版本程序。
2.使用try{...} catch(error){...}。
3.使用domains。
4.使用forever,upstart,monit,supervisor,mother.js等。
5.使用cluster。
6.使用 process.on('uncaughtException', function(err){...}); 来处理未被捕捉的错误。


参考:

 

http://shapeshed.com/uncaught-exceptions-in-node/ Uncaught Exceptions in Node.js

http://cnodejs.org/topic/4f16442ccae1f4aa270010e7 如何提高NodeJS程序的稳定性

http://deadhorse.me/nodejs/2013/04/13/exception_and_domain.html   Node.js 异步异常的处理与domain模块解析

 

http://nodejs.org/api/process.html#process_event_uncaughtexception

http://nodejs.org/api/domain.html

 

https://github.com/fengmk2/domain-middleware

https://github.com/fengmk2/graceful

https://github.com/FGRibreau/forever-webui

posted @ 2013-08-29 16:37  一片相思林  阅读(2616)  评论(0编辑  收藏  举报