From 3358b51b3c0e4a8971e644ed1a9fa9a33bf830ec Mon Sep 17 00:00:00 2001 From: Philipp Gegenfurtner Date: Fri, 9 Feb 2018 14:30:15 +0100 Subject: [PATCH] update environment variables docs to explain how to implement dotenv --- docs/docs/environment-variables.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/docs/environment-variables.md b/docs/docs/environment-variables.md index 909782f040423..055af3bf78e3f 100644 --- a/docs/docs/environment-variables.md +++ b/docs/docs/environment-variables.md @@ -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