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.
The following works for me. You can also specify the app name with --name argument, like this: pm2 start "npm run dev" --name myAppName Then you can see logs by pm2 logs myAppName Also, please don't use sudo until it's really necessary (in most cases, pm2 can work fine without sudo).
PM2 allows you to configure several different strategies for how your Node. js application should restart. By default, it restarts your application if it exits or crashes to minimize the impact to your customers in production while the source of the crash is investigated.
The default configuration file is ecosystem. core3. config. js , and is located in the root folder of lisk-service : It contains a configuration to connect to a local Lisk Core node.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With