英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论