April 20, 2020
.env.development
at the root of your project.TEST_KEY=123
npm run develop
command to set environment.For Windows -
"develop": "set GATSBY_ENV=development && gatsby develop"
For Linux -
"develop": "GATSBY_ENV=development gatsby develop"
process.env.TEST_KEY
in any js file..env.production
at the root of your project.TEST_KEY=123
npm run build
command to set environment.For Windows -
"develop": "set GATSBY_ENV=production && gatsby develop"
For Linux -
"build": "GATSBY_ENV=production gatsby build",
This is only if you want to build on local.
If you are using any providers like Netlify use the Linux version. You will also need to add environment variables in the service provider.
For Netlify it is in Site Settings > Build&Deploy > Environment