Change ENV variables at runtime

ぐ巨炮叔叔 提交于 2020-12-12 02:38:51

问题


Is it possible to inject/change the current enviroment variables in an already loaded and started NodeJS process?

Exposing an Interface within the application is not an option, restarting is also not a valid option.

The process is running inside a docker container, requiring a specific NodeJS Version is possible.

EDIT: The change must be done from outside the application source so doing process.env.ENV_VAR = "new env" is not possible.


回答1:


It isn't possible to modify the env vars of a running process. This isn't unique to NodeJS processes. It's just how env vars work on UNIX like operating systems. The vars live within the address space of the process. And while they are, typically, initially placed at a well known location near the top of the stack the current vars are likely to be at an arbitrary address in the heap. Env vars are intentionally private to each process. So unless the program provides an API for changing its env vars you can't modify them once the program is running.




回答2:


You should use a redis store shared between containers that has stored the env.

redis node repo - redis listen for changes



来源:https://stackoverflow.com/questions/59971381/change-env-variables-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!