Home > OS >  Cannot access .env variables in react app
Cannot access .env variables in react app

Time:07-25

I am trying to access the .env variable from the src folder in the frontend files but it keeps giving me undefined for some reason. The env variable is : REACT_APP_BACKEND_URL=http://localhost:5000 .

here is the folder structure:

Click!

CodePudding user response:

documentation- create react app. https://create-react-app.dev/docs/adding-custom-environment-variables

CodePudding user response:

Try using https://www.npmjs.com/package/dotenv

require('dotenv').config()
console.log(process.env)
  • Related