Skip to content

Commit

Permalink
update environment variables docs to explain how to implement dotenv
Browse files Browse the repository at this point in the history
  • Loading branch information
pgegenfurtner authored Feb 9, 2018
1 parent 12bdd35 commit 3358b51
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions docs/docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ 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.
NPM package [dotenv](https://www.npmjs.com/package/dotenv). Install the package and
require it in your `gatsby-config.js` or `gatsby-node.js` the following way on top of your file:

```
require('dotenv').config({
path: `.env.${process.env.NODE_ENV}`
});
```

Now the variables are available.

## Example

Expand Down

0 comments on commit 3358b51

Please sign in to comment.