Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 562
coder101 Avatar asked Jan 08 '19 15:01

coder101


People also ask

Is Nohup faster?

nohup is faster. The simple reason is that it depends on the internet connection between your PC and the server. Whenever the internet goes slow, the process goes slow as well.

How do I run node js app forever when console is closed?

js application locally after closing the terminal or Application, to run the nodeJS application permanently. We use NPM modules such as forever or PM2 to ensure that a given script runs continuously. NPM is a Default Package manager for Node.


1 Answers

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
like image 98
westdabestdb Avatar answered Sep 21 '22 23:09

westdabestdb