For pm2 testing purposes I am currently running both staging and production environment on the same machine. However, since both script are named the same - I will only get one instance running.
My initial thoughts was "let's add NODE_ENV to the name!", no luck, process.env.NODE_ENV is not available at this point.
Second try, let's pass --name to post-deploy script starting up, no luck, --name is ignored when starting from ecosystem.json
Not sure what I did before, this does work however;
"name": "awesome-app-" + (process.env.NODE_ENV || "local"),
...
"post-deploy": "npm install; export NODE_ENV=development; pm2 startOrRestart ecosystem.json --env development"
I think what you were missing was --force, which tells PM2 that it is okay to start the same script more than once and treat them separately.
For anyone else that runs into this, you can create 2 different apps in the apps array, but put 1 env for each app. This way you can stick with 1 file.
I worked it out using append_env_to_name: true that appends environment name to app name.
Most helpful comment
Not sure what I did before, this does work however;