Skip to content

Instantly share code, notes, and snippets.

@zenkbaries
Last active February 1, 2020 18:48
Show Gist options
  • Save zenkbaries/a3ec25242deb273edb38d4f6a99b859b to your computer and use it in GitHub Desktop.
Save zenkbaries/a3ec25242deb273edb38d4f6a99b859b to your computer and use it in GitHub Desktop.
.env with `create-react-app`

Using .env in app created with 'create-react-app'(CRA)

  • .env must be in root of the project
  • all variable in .env should be prefixed with REACT_APP_ in order to be accessible
  • CRA already include dotenv so no need to import it before using process.env.
  • Don't use sensitive info (i.e. Secret Keys) in .env for CRA. It will get exposed.
  • Use backend server to store secret keys and making calls as an added security measure.

These rule don't apply to React app that was created from scratch, not by 'create-react-app'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment