开发者

how to run node js remotely

I am running node using putty. but it doesn't work when putty session expire. How ca开发者_StackOverflow中文版n I start node js permanently, should not be terminated if putty session end.


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?


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.


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.


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


You can also run nohup:

nohup node app.js


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


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜