简体   繁体   中英

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

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?

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

the above answer is right.

  • install the npm i dotenv package.

  • import it

require("dotenv").config();

then

process.env.SOME_VARIABLE

hope this works.

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