简体   繁体   English

在.env文件中读取导出的变量nodejs

[英]Reading exported variables in .env files nodejs

Im trying to get Environment Variables from a.env file.我试图从 a.env 文件中获取环境变量。 They are saved as:它们被保存为:

export KEY=VALUE 

Reading it with dotenv returns undefined because of the 'export'由于“导出”,使用 dotenv 读取它会返回未定义

I can't modify the.env我无法修改.env

is there a way to fix this issue without duplicating the.env file and saving it without the 'export'有没有办法在不复制 .env 文件并在不使用“导出”的情况下保存它的情况下解决这个问题

dont save it as export KEY=VALUE just KEY=VALUE and then export it like this require('dotenv/config') you will be able to retrieve the env variable using this不要将它保存为export KEY=VALUE只是KEY=VALUE然后像这样导出它require('dotenv/config')你将能够使用它来检索环境变量

 process.env.KEY

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

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