问题描述:

I have a nodejs app (express application) and I running multiple instances of this same app. I want to uniquely name/identify each one of this instances so at the moment what I am doing is to generate a fixed name + its pid, this way I get something like "mynodejsapp-#10293". The thing is now I would need a name that stays the same after every restart (so I do not want to use the pid anymore) but is still unique and automaticaly generated for each instance.

Does anyone have an idea if it would be possible and how I might achieve that?

Thanks in advance

网友答案:

You could use an environment variable declared right before each deployed instance i.e.:

user$ INSTANCE_ID=1 node app.js

which you can then access via process.env

相关阅读:
Top