如何运行Node.js应用程序作为自己的进程? [英] How do I run a Node.js application as its own process?
问题描述
部署Node.js的最佳方法是什么?
What is the best way to deploy Node.js?
我有一个Dreamhost VPS(这就是他们所说的一个 VM ),我已经能够安装Node.js并设置代理。只要我保持开通节点的SSH连接,这个工作很棒。
I have a Dreamhost VPS (that's what they call a VM), and I have been able to install Node.js and set up a proxy. This works great as long as I keep the SSH connection that I started node with open.
推荐答案
2016答案:几乎所有的Linux发行版都带有systemd,这意味着永远不会再需要永久,monit等等 - 你的操作系统已经处理了这些任务。
2016 answer: nearly every Linux distribution comes with systemd, which means forever, monit, etc. are no longer necessary - your OS already handles these tasks.
创建一个 myapp.service
文件(用你的应用程序名称替换'myapp'):
Make a myapp.service
file (replacing 'myapp' with your app's name, obviously):
[Unit]
Description=My app
[Service]
ExecStart=/var/www/myapp/app.js
Restart=always
User=nobody
Group=nobody
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/var/www/myapp
[Install]
WantedBy=multi-user.target
将您的服务文件复制到 / etc / systemd / system
文件夹中。
Copy your service file into the /etc/systemd/system
folder.
使用 systemctl daemon-reload
告诉systemd关于新服务。
Tell systemd about the new service with systemctl daemon-reload
.
开始它与 systemctl启动myapp
。
使其运行启动与 systemctl启用myapp
。
查看日志与 journalctl -u myapp
详细信息请访问: 如何在Linux,2016版本上部署节点应用
More details at: How we deploy node apps on Linux, 2016 edition
这篇关于如何运行Node.js应用程序作为自己的进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!