1、部署
package.json
1 | "scripts": { |
ecosystem.config.js1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module.exports = {
apps: [{
name: "yjl",
script: "./app.js",
watch: true,
env: {
NODE_ENV: "development",
PORT: 443,
API_URL:"https://backend.xxx",
SOURCE_PATH:"./src"
},
env_test: {
NODE_ENV: "test",
PORT: 443,
API_URL:"https://backend.xxx",
SOURCE_PATH:"./dist"
},
env_production: {
NODE_ENV: "production",
PORT: 4000,
API_URL:"http://backend.xxx",
SOURCE_PATH:"./dist"
},
autorestart: true,
log_date_format: "YYYY-MM-DD HH:mm Z"
}]
}
app.js
1 |
|
2、使用pm2
1、保存脚本
1 | pm2 save |
2、创建开机启动脚本
1 | pm2 startup |
3、设置开机自动启动(centos 7+)1
systemctl enable pm2-root.service
4、重启koa21
pm2 restart yjl
5、重新搭建启动koa21
2pm2 delete yjl
npm run server
6、查看错误日志1
2
3pm2 show yjl #查看log的输出目录
cd /root/.pm2/logs/ && cat yjl-error-0.log