What's the best approach to keep node running in the background - nohup vs. forever vs. pm2? [closed]
Asked Answered
C

1

9

I've read many posts that talk about keeping node running in the background using nohup, forever and pm2. But I'm still uncertain which is the optimal choice and would appreciate some guidance.

Background - running a MEAN stack app on an Apache server which uses Ubuntu version 16. App.js location is /var/www/. I'm currently using forever to keep the app running in the background when I exit the terminal. I understand that if I use nohup, the command would be

nohup node /var/www/<project_name>/app.js > stdout.txt 2> stderr.txt &

What I want to ensure is that regardless of 1) how I exit the terminal (by typing exit or simply clicking the X on the top right) and 2) which operating system the app is deployed on, no background service will terminate in a way that disrupts my app when I exit the terminal. To that end, what's the best approach to running the app? nohup, forever or pm2? I also understand that some people have a preference for pm2 over forever. What does pm2 offer than forever doesn't?

Complexioned answered 8/1, 2019 at 15:2 Comment(1)
supervisord is better.Mielke
D
11

PM2 is much more advanced and it has the PM2-Web interface to manage it.

PM2 does but Forever doesn't:

  • Graceful/rolling restarts
  • OS startup script support
  • Remote deploy
  • Multiple deploys/revert
  • Cluster mode
  • Metrics
Demott answered 8/1, 2019 at 15:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.