diff --git a/docs/docs/environment-variables.md b/docs/docs/environment-variables.md index 9d002b096f75b..a47edb02251d9 100644 --- a/docs/docs/environment-variables.md +++ b/docs/docs/environment-variables.md @@ -47,6 +47,10 @@ In addition to these Project Environment Variables defined in `.env.*` files, yo OS Env Vars. OS Env Vars which are prefixed with `GATSBY_` will become available in browser JavaScript. +```shell:title=.env.* +GATSBY_API_URL=https://dev.example.com/api +``` + #### Server-side Node.js Gatsby runs several Node.js scripts at build time, notably `gatsby-config.js` and `gatsby-node.js`. @@ -77,31 +81,47 @@ Now the variables are available on `process.env` as usual. ## Example -```shell -# Example .env.development file +Please note that you shouldn't commit `.env.*` files to your source control and rather use options given by your CD provider (e.g. Netlify with its [build environment variables](https://www.netlify.com/docs/continuous-deployment/#build-environment-variables)). -API_URL=https://dev.example.com/api +```shell:title=.env.development +GATSBY_API_URL=https://dev.example.com/api +API_KEY=927349872349798 ``` -```shell -# Example .env.production file - -API_URL=https://example.com/api +```shell:title=.env.production +GATSBY_API_URL=https://example.com/api +API_KEY=927349872349798 ``` -These variables will be available to your site as `process.env.API_URL`: +`GATSBY_API_URL` will be available to your site (Client-side and server-side) as `process.env.GATSBY_API_URL`: ```jsx -// usage +// In any front-end code render() { return (
+