如何远程运行node.js
我正在使用 putty 运行节点。但当 Putty 会话过期时它不起作用。如何永久启动节点js,如果putty会话结束则不应终止。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我昨天刚刚使用 Forever > 解决了这个问题http://blog.nodejitsu.com/keep-a-nodejs -server-up-with-forever
太棒了。
安装:
npm install Forver
运行:
永远启动 yourServer.js
用于检查其是否正在运行:
永远列表
酷吧?
I just solved that issue yesterday using Forever > http://blog.nodejitsu.com/keep-a-nodejs-server-up-with-forever
It's awesome.
For Installing:
npm install Forver
For running:
forever start yourServer.js
For checking if its running:
forever list
cool eh?
通常,您使用守护程序来保持其运行。正确的答案取决于远程计算机运行的操作系统类型(Windows?)。
最好在 *unix 上运行 node.js。
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.
Raynos 和 nEEbz 建议您还可以尝试使用 GNU Screen。这非常方便,特别是当您使用 putty 连接到远程服务器时。查看此屏幕教程了解更多信息。
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.
这是对“屏幕”的快速而温和的介绍。
在 ubuntu 中,如果您需要安装它,请使用: apt-get install screen
第一次使用:
打印出一堆内容,然后另一个 shell 提示
$ node ./myapp.js
现在您的节点应用程序正在运行
您想要编辑其他一些代码?
control-a c
窗口将被清除,现在您将看到另一个 shell 提示符。节点仍在运行...
$ edit public/somewebfile.html
保存它,仍在编辑器中
返回节点
屏幕切换回运行节点的屏幕
需要离开办公室几分钟
屏幕断开连接,但是nodejs和编辑器仍在运行...
回到家...
现在想连接工作吗再次查看 nodejs shell 屏幕,或者 control-a control-a 切换回该编辑器
control-a ?显示可用命令,或阅读不错的手册页:man screen
Here is a quick and gentle introduction to "screen" .
In ubuntu, if you need to install it, use: apt-get install screen
First use:
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
screen switches back to the screen running node
need to leave the office for a few minutes
screen disconnects, but nodejs and the editor are still running...
back at home... want to connect to work
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
您还可以运行 nohup:
You can also run nohup:
如果您在执行
npm install Forever
时遇到错误,请执行npm install Forever -g
我遇到了这个问题。
https://www.npmjs.com/package/forever
If you get an error when you do
npm install Forever
, donpm install forever -g
I got that problem.
https://www.npmjs.com/package/forever
使用
PM2
只需在服务器上安装
pm2
并运行应用程序,如下所示:pm2 start app.js
您还可以从 Web 面板监控您的应用程序
PM2(进程管理器)
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)