当前位置: 动力学知识库 > 问答 > 编程问答 >

node.js - How to identify a nodejs instance

问题描述:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: