Search code examples
javascriptnode.jsreactjsenvironment-variablesdotenv

Cannot access environment variable in desired file


I am trying to access environment variables in my Display.js, I have created a .env file in the root of my project, however, process.env is not logging my env variable.

.env inside of root folder of my project:

https://i.sstatic.net/WaKMQ.png

Display.js (located in same folder as .env):

https://i.sstatic.net/MJG80.png

Image of my folders:

https://i.sstatic.net/IlAsZ.png


Solution

  • .env must be located of project root directory