I'm trying to use pm2 to manage a node.js cluster
pm2 start . -i 3
I'm currently running the app on heroku and using a Procfile with the above command, but I cannot figure out how to configure pm2 to use the existing PORT env var. Something like pm2 start . -p $PORT
What am I missing?
You can use an environment variable. For example:
NODE_PORT=3002 pm2 start -i 0 app.js
Here is how to read the value in app:
console.log(process.env.NODE_PORT);
Or, if you are building an Express app:
PORT=3002 pm2 start -i 0 ./bin/www
Express loads PORT
automatically when the application starts.