Skip to content

Commit

Permalink
Update environment-variables.md
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews authored Nov 3, 2017
1 parent c915b63 commit ec268ad
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions docs/docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ You can easily provide environment variables to your site.

For JavaScript loaded into the browser, just add a `.env.development` and/or `.env.production` file in your root folder for development or production builds respectively. The environment variables are embedded during build time using Webpack's [DefinePlugin](https://webpack.js.org/plugins/define-plugin/). Because these variables are provided at build time, you will need restart your dev server or rebuild your site after changing them.

To add environment variables for the JavaScript run in node.js, e.g. in `gatsby-config.js` or `gatsby-node.js`, you can use the NPM package [dotenv](https://www.npmjs.com/package/dotenv). Once you've installed dotenv and followed their setup instructions, you can use your environment variables in the same way as shown in the example below.
In addition to `.env.*` files, any variable in the environment prefixed with `GATSBY_` will be made available in browser JavaScript.

To add environment variables for the JavaScript run in node.js, e.g. in `gatsby-config.js` or `gatsby-node.js`, you can add environment variables the normal ways e.g. when calling gatsby on the command line or by adding environment variables through your hosting/build tool.

If you want to access variables in `.env.*` files in your node.js code, use the NPM package [dotenv](https://www.npmjs.com/package/dotenv). Once you've installed dotenv and followed their setup instructions, you can use your environment variables in the same way as shown in the example below.

## Example

Expand All @@ -25,8 +29,6 @@ API_URL=https://example.com/api

These variables will be available to your site as `process.env.API_URL`.

In addition any variable in the environment prefixed with `GATSBY_` will be available.

## Example

```
Expand Down

0 comments on commit ec268ad

Please sign in to comment.