I imagine you got this working by now, but for anyone else that finds this, you set your default environment variables in a
.env file at the root of your “create-react-app” project.
To separate out the variables used when using
npm start and
npm run build you can create two more env files –
npm start will set
development, and so it will automatically use the
.env.development file, and
npm run build sets
production, and so it will automatically use
.env.production. Values set in these will override the values in your
If you’re working with other people, and have values specific to your machine only, you can override values in
.env.production by adding those values to a new file –
EDIT: I should point out that the environment variables you have set must start with “REACT_APP_”, eg. “REACT_APP_MY_ENV_VALUE”.