Though if you're passing the environment you may want to consider leveraging environment variables. With this you create a variable which can be accessed by any process in that environment with process.env.*.
var config=require('./config.json')[process.env.NODE_ENV || 'dev'];
db.connect(config.db.hosts, config.db.database);
Then you'd set the variable in your environment via shell:
export NODE_ENV=staging
pm2 start app.js
The environment variable will last as long as your session. So you'll have to set it in the ~/.bashrc file for that user for the variable to persist. This will set the variable every session.
PM2 has a deploy system which allows you to set an environment variable each time before your app is daemonized. This is how daemons in POSIX systems typically take parameters, because those parameters aren't lost with the process. Given with your circumstance it might not matter so much, but its a good practice.
Moreover you should consider stop/starting locally, and restarting(if in cluster mode) whenever possible to prevent downtime when in production.
//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
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:
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.