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

Time:01-05

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?

CodePudding user response:

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

CodePudding user response:

the above answer is right.

  • install the npm i dotenv package.

  • import it

require("dotenv").config();

then

process.env.SOME_VARIABLE

hope this works.

  • Related