21

我需要能够使用 pm2 启动下面的应用程序,但不知道如何使用 pm2 启动它。

node --expose-gc bin/www arg1 arg2 arg3

我知道--node-args但我认为仅适用于--expose-gc。

4

4 回答 4

29

经过一番挖掘,我发现我正在寻找的是linux上的双破折号。

正常的代码,

node --expose-gc bin/www arg1 arg2 arg3

使用 pm2 的相同代码

pm2 start bin/www --node-args="--expose-gc" -- arg1 arg2 arg3

您必须放入的所有 v8 参数--node-args和要从您那里获取的所有脚本 argsprocess.argv都必须放在双破折号之后。

我希望将来他们实现一些链接--script-args =“arg1 arg2 arg3”。对于那些不是Linux专家的人来说会非常好。

于 2014-12-29T15:44:29.207 回答
20

另一种方法是在您指定args密钥的位置创建应用程序声明 json 文件。查看 PM2 站点上的文档

文件示例pm2.json

{
  "apps" : [{
    "name"        : "appname",
    "script"      : "app.js",
    "args"        : ["-s", "123"],
    "node_args"   : "--harmony",
    "merge_logs"  : true,
    "cwd"         : "/this/is/a/path/to/start/script",
    "env": {
        "NODE_ENV": "production"
    }
  }]
}

并按如下方式运行:

$ pm2 start pm2.json
于 2015-09-06T06:42:47.857 回答
2

您可以在之后添加任何自定义参数-x --

pm2 start app.js -x -- --prod

和节点参数为--node-args="--harmony"

pm2 start app.js --node-args="--harmony"

两个都

pm2 start app.js --node-args="--harmony" -x -- --prod

于 2016-07-19T05:45:06.700 回答
1

我不得不在我的 pm2 process.js 中暴露-gc,所以我做了以下事情:

{
  "apps" : [
    {
      "name"        : "app",
      "script"      : "bin/www",
      "instances"   : 2,
      "exec_mode"   : "cluster",
      "watch"       : false,
      "node_args"   : "--expose-gc",
      "env"         : {"NODE_ENV": "development"}
    }
  ]
}
于 2016-05-30T05:09:48.553 回答