Node JS auto restart all forever JS process when server goes down / crashes

前端 未结 6 932
眼角桃花
眼角桃花 2021-02-07 05:37

I am using forever js to keep my node server running 24/7 on AWS EC2.

I use this command

forever start index.js

However, I notice that

6条回答
  •  长情又很酷
    2021-02-07 06:24

    I'd suggest the usage of PM2

    This is the best option to run on a production server.

    What are the advantages of running your application this way?

    • It's easy to setup and run.
    • PM2 will automatically restart your application if it crashes.
    • PM2 will keep a log of your unhandled exceptions - in this case, in a file at /home/safeuser/.pm2/logs/app-err.log.
    • With one command, PM2 can ensure that any applications it manages restart when the server reboots. Basically meaning your node application will start as a service.

    ref: https://www.digitalocean.com/community/tutorials/how-to-use-pm2-to-setup-a-node-js-production-environment-on-an-ubuntu-vps

提交回复
热议问题