如何将节点v8 args和脚本args传递给pm2?

Har*_*nch 18 production node.js pm2

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

node --expose-gc bin/www arg1 arg2 arg3
Run Code Online (Sandbox Code Playgroud)

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

Har*_*nch 24

经过一番挖掘,我发现我正在寻找的是Linux上的双击.

普通代码,

node --expose-gc bin/www arg1 arg2 arg3
Run Code Online (Sandbox Code Playgroud)

使用pm2的相同代码

pm2 start bin/www --node-args="--expose-gc" -- arg1 arg2 arg3
Run Code Online (Sandbox Code Playgroud)

所有你必须放入的v8参数--node-args以及从process.argv你那里获取的所有程序都需要在双击之后放置.

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


psu*_*lek 20

另一种方法是创建应用程序声明json文件,您可以在其中指定args键.查看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"
    }
  }]
}
Run Code Online (Sandbox Code Playgroud)

并运行如下:

$ pm2 start pm2.json
Run Code Online (Sandbox Code Playgroud)