I am using pm2 to start my app but i am not able to pass argument to it. the command I am using is pm2 start app.js -- dev. Though this works with forever.
You can send arguments to your script by passing them after --
. For example: pm2 start app.js -i max -- -a 23 // Pass arguments after -- to app.js
I always use PM2 to run my python scripts in Linux environment. So consider a script has a single parameter and needs to run continously after some amount if time, then we can pass it like this:
pm2 start <filename.py> --name <nameForJob> --interpreter <InterpreterName> --restart-delay <timeinMilliseconds> -- <param1> <param2>
filename.py
is Name of the python script, without <> symbols, I want to run using PM2
nameForJob
is the Meaningful name for the job, without <> symbols
InterpreterName
is the python interpreter for running script, usually it is python3
in linux
timeinMilliseconds
is the time our script needs to wait and re-run again
param1
is the first parameter for the script
param2
is the second parameter for the script.
If you want to pass node arguments from CLI then
pm2 start myServer.js --node-args="--production --port=1337"
.
Edited
you can add any arguments after --
pm2 start app.js -- --prod --second-arg --third-arg
Sails docs for deploymemt.
From the pm2 docs
//Inject what is declared in env_production
$ pm2 start app.js --env production
//Inject what is declared in env_staging
$ pm2 restart app.js --env staging
You can pass args for node just like that:
NODE_TLS_REJECT_UNAUTHORIZED=0 NODE_ENV=dev pm2 start server.js --name web-server
You need to start pm2 with something like: pm2 start app.js --name "app_name" -- arg1 arg2
Then in your code, you can get your args with: console.log(process.argv);
process.argv is a list like this: [ '/usr/local/bin/node', '/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js', 'arg1', 'arg2' ]