15

I am running node using putty. but it doesn't work when putty session expire. How can I start node js permanently, should not be terminated if putty session end.

7 Answers 7

20

I just solved that issue yesterday using Forever > http://blog.nodejitsu.com/keep-a-nodejs-server-up-with-forever

It's awesome.

  1. For Installing: npm install Forver

  2. For running: forever start yourServer.js

  3. For checking if its running: forever list

cool eh?

Sign up to request clarification or add additional context in comments.

1 Comment

Nice! Looks like it can be used for any process, not just node.js.
3

Generally you use a deamon to keep it running. A proper answer depends on what type of OS your remote machine is running (windows ?).

It's best to run node.js on *unix.

Comments

3

Among what Raynos and nEEbz are suggesting you can also try to use GNU Screen. This is very handy especially if you are using putty to connect to remote server. Check out this screen tutorial for more information.

Comments

3

Here is a quick and gentle introduction to "screen" .

In ubuntu, if you need to install it, use: apt-get install screen

First use:

$ screen

bunch of stuff prints out, then another shell prompt

$ node ./myapp.js

now your node app is running

You want to edit some other code?

control-a c

the window clears, and you now have another shell prompt. node is still running....

$ edit public/somewebfile.html

save it, still in editor go back to node

control-a control-a

screen switches back to the screen running node

need to leave the office for a few minutes

control-a control-d
(screen detaches from your location... processes remain attached)
$ logout

screen disconnects, but nodejs and the editor are still running...

back at home... want to connect to work

> ssh work.some.where
> screen -D -R
screen reconnecting....

now you see the nodejs shell screen again, or control-a control-a to switch back to that editor

control-a ? shows available commands, or read the nice man page: man screen

Comments

2

You can also run nohup:

nohup node app.js

Comments

1

If you get an error when you do npm install Forever, do npm install forever -g

I got that problem.

https://www.npmjs.com/package/forever

Comments

0

Use PM2

just install pm2 on the server and run app like this : pm2 start app.js

you can also monitor your application from the web panel

PM2 (proccess manager)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.