简体   繁体   English

NodeJS 中的环境变量

[英]Env Variables in NodeJS

I'm new to NodeJS and trying to understand the internal working of the system.我是 NodeJS 的新手,正在尝试了解系统的内部工作原理。 Normally we create a.env file or some other configuration file to keep and manage secrets.通常我们创建一个 .env 文件或一些其他配置文件来保存和管理秘密。 The same environment values can be kept at the system level like using "export" command on mac.可以在系统级别保留相同的环境值,就像在 mac 上使用“export”命令一样。

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.我想了解的是,当我们从配置文件或系统本身启动程序时,NodeJS 如何加载和读取这些值。

You can dig through the NodeJS source code to actually see how the environment is provided to NodeJS, eg here through the RealEnvStore class .您可以深入了解 NodeJS 源代码,以实际了解如何为 NodeJS 提供环境,例如此处通过RealEnvStore class As you can see uv_os_getenv abstracts access to the env depending on the actual operation system.如您所见, uv_os_getenv根据实际操作系统抽象化了对 env 的访问。

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 .至少在 unix 系统上, uv_os_getenv使用environ变量,它基本上引用了节点进程可用的所有环境变量,如您在此处所见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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