I need to be able to start the app below with pm2 but don't know how to start it with pm2.
node --expose-gc bin/www arg1 arg2 arg3
I know about --node-args
but I think is only for --expose-gc.
I need to be able to start the app below with pm2 but don't know how to start it with pm2.
node --expose-gc bin/www arg1 arg2 arg3
I know about --node-args
but I think is only for --expose-gc.
After some digging, I've found out that what I was looking for was the double dash on linux.
The normal code,
node --expose-gc bin/www arg1 arg2 arg3
The same code using pm2
pm2 start bin/www --node-args="--expose-gc" -- arg1 arg2 arg3
All v8 arguments you have to put inside --node-args
and all scrips args to be grabbed from process.argv
you have to put after the double dash.
I hope that in the future they implement something link --script-args="arg1 arg2 arg3". Would be very nice for those that isn't a linux expert.
Another way is to create application declaration json file where you specify args
key. Look at documentation on PM2 site.
Example of pm2.json
file:
{
"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"
}
}]
}
And run it as follows:
$ pm2 start pm2.json
you can add any custom arguments after -x --
,
pm2 start app.js -x -- --prod
and node argument as --node-args="--harmony"
pm2 start app.js --node-args="--harmony"
Both
pm2 start app.js --node-args="--harmony" -x -- --prod
I had to expose-gc in my pm2 process.js so I had the do the following:
{
"apps" : [
{
"name" : "app",
"script" : "bin/www",
"instances" : 2,
"exec_mode" : "cluster",
"watch" : false,
"node_args" : "--expose-gc",
"env" : {"NODE_ENV": "development"}
}
]
}
© 2022 - 2024 — McMap. All rights reserved.