Categories
create-react-app environment-variables reactjs

React env variables with .env

I’m trying to follow docs on adding env variables from react-create-app without success:

https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables

enter image description here

  • inside root of the document I have a “.env” file (default .env properties)
  • .env file contains only one variable ‘REACT_APP_API_HOST=http://localhost:8080
  • trying to access process.env inside my app (created with create react app) gives me undefined

This is app.js where I’m trying to access process.env without success.

I can’t access process.env inside the code. Is there any working example on how to do it?