How to run Node.js as a background process and never die?
I connect to the linux server via putty SSH. I tried to run it as a background process like this:
$ node server.js &
However, after 2.5 hrs the terminal becomes inactive and the process dies. Is there anyway I can keep the process alive even with the terminal disconnected?
---
**Edit 1**
Actually, I tried `nohup`, but as soon as I close the Putty SSH terminal or unplug my internet, the server process stops right away.
Is there anything I have to do in Putty?
---
**Edit 2 (on Feb, 2012)**
There is a `node.js` module, [forever][1]. It will run node.js server as daemon service.
[1]: https://github.com/nodejitsu/forever
More
1 Expert Answer
Ahmed A. answered 17d
Tutor
New to Wyzant
Arabic and Linux/Unix Tutor with Telecom Engineering Experience
PM2 is a production process manager for Node.js apps and is designed to keep apps alive, restart them, manage logs, and configure startup on reboot.
Install PM2:
npm install -g pm2
Start your app:
cd /path/to/your/app
pm2 start server.js --name my-node-app
Check status:
pm2 status
View logs:
pm2 logs my-node-app
Make it restart after server reboot:
pm2 startup
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Nigel C.
I have used pm2 with some success. Here is the website and npm package below. Pretty straight forward to use. pm2 - https://pm2.io/ npm - https://www.npmjs.com/package/pm205/30/23