我想使用pm2和环境变量比如--nouse-idle-notification
或者 --max-old-space-size=2048
来启动node。
但是,无论我怎么做,都不能将node变量传递给它。我使用pm2和配置文件启动我的应用程序。配置文件看起来像这样:
{
"apps" : [{
"env": {
"NODE_PATH": "/usr/bin/node",
"interpreter_args": "--max-old-space-size=2048 --nouse-idle-notification"
},
"env_development": {
"NODE_ENV": "development"
},
"env_production" : {
"NODE_ENV": "production",
"APP_TYPE": "web"
},
"exec_mode" : "fork",
"name" : "MyApp",
"script" : "/opt/myapp/app.js",
"watch" : false,
"out_file" : "/var/log/app.log",
"error_file" : "/var/log/app.log",
"combine_logs": true,
"node_args": "--max-old-space-size=2048 --nouse-idle-notification",
"args": "--max-old-space-size=2048 --nouse-idle-notification"
}]
}
正如您所看到的,我尝试以多种方式传递节点变量。
然后我使用以下命令启动应用程序:
pm2 restart pathtojsonfile --env production
一切都正常启动,我的代码中出现了“MY_APP”等变量。但是,当我使用“top”查看进程时,我只看到:
node /opt/myapp/app.js
当我使用forever或手动启动应用程序时,可以看到进程如下所示:
node --max-old-space-size=2048 --nouse-idle-notification /opt/myapp/app.js
pm2是否只是没有显示这些node参数,还是确实没有传递进去?(pm2启动的进程使用更少的内存)
systemd
.service
文件的内容。 - Mark Stosberg