node.jsmultiprocessingpm2

node app instance name when running via pm2 cluster


I have backend node app, that is run by pm2 in cluster mode. I'm running fixed 2 instances.

Is there a way to identify instance name or number from within executed app?

App name is "test", I would like to get from within the app "test 1" and "test 2" for given instance.


Solution

  • You'll need to use two environment variables set by pm2: