Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to run Node.js as a background process and never die?

I connect with the Linux server through putty SSH. I attempted to run it as a background process like this:

$ node server.js &


In any case, after 2.5 hrs the terminal becomes inert and the interaction passes on. Is there any way I can keep the interaction alive even with the terminal detached?

In reality, I attempted nohup, however when I close the Putty SSH terminal or unplug my web, the server process stops immediately.

Is there anything I need to do in Putty?
by

2 Answers

rahul07
Simple solution (if you are not interested in coming back to the process, just want it to keep running):

nohup node server.js &

There's also the jobs command to see an indexed list of those backgrounded processes. And you can kill a backgrounded process by running kill %1 or kill %2 with the number being the index of the process.

Powerful solution (allows you to reconnect to the process if it is interactive):

screen

You can then detach by pressing Ctrl+a+d and then attach back by running screen -r

Also consider the newer alternative to screen, tmux.
kshitijrana14
another solution disown the job
$ nohup node server.js &
[1] 1711
$ disown -h %1

Login / Signup to Answer the Question.