我想用pm2和环境变量(如 --nouse-idle-notification
或 --max-old-space-size=2048
。)启动节点。
但是,无论我做什么,它都不会传递节点变量。我使用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"
}]
}
(如您所见,我尝试以多种方式传递节点变量)
i然后使用:
启动应用程序pm2 restart pathtojsonfile --env production
一切都正确地启动了,我看到了" my_app"之类的变量。在我的代码中。但是,现在,当我以" top"查看该过程时我只看到:
node /opt/myapp/app.js
当我永远或手动启动应用程序时,我可以看到类似的过程:
node --max-old-space-size=2048 --nouse-idle-notification /opt/myapp/app.js
pm2只是没有显示那些节点参数,还是真的没有通过?(PM2启动过程使用较少的内存)
以下是用node-args
启动pm2的扩展命令pm2 start app.js --node-args="--max-old-space-size=4096"
通过使用" node_args":" - 最大的空间size = 2048 - nouse-idle-notification"您做了正确的事情,并且考虑了这些参数。
pm2重命名该过程并将指定的节点参数放在进程标题中。