directives
1 | pm2 start index.js |
env variables
将node.js应用封装成模块ecosystem.config.js (也可以直接用json)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17module.exports = {
apps : [
{
name: "myapp",
script: "./app.js",
watch: true,
env: {
"PORT": 3000,
"NODE_ENV": "development"
},
env_production: {
"PORT": 80,
"NODE_ENV": "production",
}
}
]
}
在启动命令时使用env_后面的字符串作为标识1
pm2 start ecosystem.config.js --env production
pm2 plus
know more about pm2.io
开机自启
键入下面的命令生成startup脚本1
pm2 startup
提示执行配置命令,如1
2[PM2] To setup the Startup Script, copy/paste >the following command:",
sudo env >PATH=$PATH:/usr/local/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u username --hp /home/username
按照提示执行提示的命令, 执行后终端列出已安装的服务信息
Caution!升级nodejs对startup有影响1
2
3pm2 unstartup
pm2 startup