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. It will run node.js server as daemon service.
Run command systemctl start node-app-service-name to start the service, the node-app-service-name is the service file name as above. If you want to run node in background every time when the Linux OS startup, you can run the command systemctl enable node-app-service-name in a terminal to achieve this.
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.
Major Node. js versions enter Current release status for six months, which gives library authors time to add support for them. After six months, odd-numbered releases (9, 11, etc.) become unsupported, and even-numbered releases (10, 12, etc.)
The short answer is “NO.” The long answer is, “NO, it's not dead, and it probably will never die.” Node. js is just as relevant to coding in 2021 and beyond, even if the hype around it has stabilized slightly.
nohup node server.js > /dev/null 2>&1 &
nohup
means: Do not terminate this process even when the stty is cut off. > /dev/null
means: stdout goes to /dev/null (which is a dummy device that does not record any output). 2>&1
means: stderr also goes to the stdout (which is already redirected to /dev/null
). You may replace &1 with a file path to keep a log of errors, e.g.: 2>/tmp/myLog
&
at the end means: run this command as a background task. 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.
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