简体   繁体   中英

Env Variables in NodeJS

I'm new to NodeJS and trying to understand the internal working of the system. Normally we create a.env file or some other configuration file to keep and manage secrets. The same environment values can be kept at the system level like using "export" command on mac.

what I'm trying to understand is how NodeJS loads and reads these value when we start the program either from a configuration file or from system itself.

You can dig through the NodeJS source code to actually see how the environment is provided to NodeJS, eg here through the RealEnvStore class . As you can see uv_os_getenv abstracts access to the env depending on the actual operation system.

At least on unix systems uv_os_getenv uses the environ variable which basically references all the environment variables that are made available to the node process as you can see here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM