无法在REACT/NODE应用程序的.env文件中找到process.env.SOME_VARIABLE。

huangapple go评论87阅读模式
英文:

Cant find process.env.SOME_VARIABLE in the file .env in a REACT/NODE application

问题

我的代码库一直在使用'process.env.SOME_VARIABLE'来引用环境变量。在React和Node项目中都有一个.env文件,但我看不到大部分在项目配置文件中以这种格式'process.env.SOME_VARIABLE'使用的变量在文件中。

我尝试在Node控制台中使用process.env,但我只得到了本地环境的元数据,比如系统设置、版本等,但我找不到SOME_VARIABLE或其他与项目相关的变量在列表中。

你能帮我找出SOME_VARIABLE可能在哪里定义的以及它是如何定义的吗?

英文:

My codebase has been referring to env variables using 'process.env.SOME_VARIABLE'. In both react and node projects there is a .env file but I can't see most of the variables in the file which are being used in the project config file in this format 'process.env.SOME_VARIABLE'

I tried process.env in node console, but I get metadata of the local environment like system setup, versions, etc. but I can't find SOME_VARIABLE, or any other project-related variables in that list.

Can you please help me figure out where could this SOME_VARIABLE be defined and what is defined?

答案1

得分: 2

你需要在Node.js环境中使用dotenv.env文件中解析环境变量,然后SOME_VARIABLE将在process.env.SOME_VARIABLE中可用。

英文:

You need to parse your env variables from .env file using dotenv in nodejs environment then SOME_VARIABLE will available in process.env.SOME_VARIABLE

答案2

得分: 1

以上答案是正确的。

  • 安装 npm i dotenv 包。

  • 导入它

require("dotenv").config();

然后

process.env.SOME_VARIABLE

希望这能正常工作。

英文:

the above answer is right.

  • install the npm i dotenv package.

  • import it

require("dotenv").config();

then

process.env.SOME_VARIABLE

hope this works.

huangapple
  • 本文由 发表于 2023年1月5日 10:59:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75013444.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定