regarding running terminal commands on vps

Posted January 31, 2015 4.3k 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?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
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.