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?
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.
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.
PM2 is much more advanced and it has the PM2-Web interface to manage it.
PM2 does but Forever doesn't:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With