ram*_*eer 5 environment-variables node.js
Can we reload environment variables (process.env) with the updated values without restarting the nodejs app or server ?
In other words, I have created a new environment variable (NEW_VARIABLE) and have set a value in my Windows 7 machine. Now I have written a function to read the environment variable as below in my NodeJS application.
setInterval(() => {
console.log(process.env.NEW_VARIABLE);
}, 5000);
Run Code Online (Sandbox Code Playgroud)
小智 0
是的,您可以,请参阅下面的代码,我们运行 2 个循环,一个用于读取,另一个用于递增变量。
setInterval(() => {
process.env.NEW_VARIABLE++;
},
1000);
setInterval(() => {
console.log(process.env.NEW_VARIABLE);
},
1000);
Run Code Online (Sandbox Code Playgroud)
当您更新变量时,下一次读取将被更新。
除非您使用一些具有缓存行为的软件包,否则我已经在一些软件包中看到了这一点。
| 归档时间: |
|
| 查看次数: |
3862 次 |
| 最近记录: |