我想用 pm2 和环境变量(如--nouse-idle-notificationor )启动节点--max-old-space-size=2048。
但是,无论我做什么,它都不会传递节点变量。我用 mp2 和一个配置文件启动我的应用程序。配置文件如下所示:
{
"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"
}]
}
Run Code Online (Sandbox Code Playgroud)
(如您所见,我尝试以多种方式传入节点变量)
然后我用以下命令启动应用程序:
pm2 restart pathtojsonfile --env production
Run Code Online (Sandbox Code Playgroud)
一切都正常启动,我在我的代码中看到了像“MY_APP”这样的变量。但是,现在当我用“top”查看过程时,我只看到:
node /opt/myapp/app.js
Run Code Online (Sandbox Code Playgroud)
当我永久或手动启动应用程序时,我可以看到如下过程:
node --max-old-space-size=2048 --nouse-idle-notification /opt/myapp/app.js
Run Code Online (Sandbox Code Playgroud)
pm2 …