gpt4 book ai didi

node.js - 带有 systemd 和传递 Node 参数的 pm2

转载 作者:行者123 更新时间:2023-12-04 14:31:27 31 4
gpt4 key购买 nike

我想用 pm2 和环境变量(如 --nouse-idle-notification)启动 Node 或 --max-old-space-size=2048 .

但是,无论我做什么,它都不会传递 Node 变量。我用 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"
}]
}

(如您所见,我尝试以多种方式传入 Node 变量)

然后我用以下命令启动应用程序:
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 只是没有显示这些 Node 参数还是它们真的没有传入? (pm2 启动的进程使用较少的内存)

最佳答案

下面是使用 node-args 启动 pm2 的 extact 命令

pm2 start app.js --node-args="--max-old-space-size=4096"

关于node.js - 带有 systemd 和传递 Node 参数的 pm2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41030594/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com