Asked • 04/19/19

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

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/pm2
Report

05/30/23

1 Expert Answer

By:

Ahmed A. answered • 17d

Tutor
New to Wyzant

Arabic and Linux/Unix Tutor with Telecom Engineering Experience

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.