Solvedpm2 Pass instance id to app as environment variable

When starting pm2 with multiple instances for a specific app, it would really help a lot if the app itself would get an Int representing its id in the series of instances.

For example, given a pm2 configuration that loads 3 instances:

app1 - instance id 0
app2 - instance id 1
app3 - instance id 2

In the node-config module they use the NODE_APP_INSTANCE env variable, but setting it in the pm2.json file itself can also work.

21 Answers

✔️Accepted Answer

process.env.pm_id does that :)

More Issues: