ringa_lee2017-04-17 11:08:17
Node is a single process. If there is an exception, it is easy to crash the entire process, so exception handling must be done well. Compared with forever, pm2 is more recommended. If a single process hangs up, it will not be able to serve. pm2 can start multiple process services with one parameter ( No need to write any code! !), if one is down, there will be other services, and pm2 will also monitor the status of the process.
https://github.com/Unitech/pm2
http://devo.ps/blog/2013/06/26/goodbye-node-forever-hello-pm2.html
怪我咯2017-04-17 11:08:17
It is recommended to check the log. If the log is not detailed enough, you can consider modifying the program to log errors, etc. The simplest way is to use console.log.
In addition, forever can automatically restart the service.
ringa_lee2017-04-17 11:08:17
The single thread of node causes it to crash directly once an error is encountered. Moreover, due to its event queue mechanism, errors are often not caught using try and catch, so the err of each callback function must be determined to handle the error. function, it is best to specifically define a series of exception events to specifically handle exceptions.
Forever can indeed automatically restart the service, but I don’t know if there is something wrong with the way I use it. When I used it to build a website, once an error occurred, the service would restart, but the session and everything else would be lost, which was a headache...