regarding running terminal commands on vps

January 31, 2015 2k views

regarding running terminal commands on vps (for e.g. "node server.js")
I can run those commands using putty via my pc, but when I close putty, the node closes too. Can it be that I close my putty and the node still continues to run?

2 Answers

It depends on the kind of code you run. Some applications run inside your session, so when you disconnect, they stop. Others run on the background, and continue to do so if you disconnect.

Running "node server.js" is a command connected to your session, and it will stop once you disconnect. If that's not what you want, you need to set up some kind of service or daemon that will run your for you after you disconnect.

You can do

screen -S node

and then execute your command.

Then, press control-d

After that, you can close putty.

If you want to go back to your screen session, do screen -r node

You can then do control-c to stop it, etc.

Have another answer? Share your knowledge.