search

Home  >  Q&A  >  body text

node.js - node为什么经常跑着跑着自己断了

如题求解。是因为服务器问题吗。。我的单核的服务器速度凑活。是并发量的问题还是?

PHPzPHPz2787 days ago645

reply all(3)I'll reply

  • ringa_lee

    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

    reply
    0
  • 怪我咯

    怪我咯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.

    reply
    0
  • ringa_lee

    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...

    reply
    0
  • Cancelreply