DEV Community

Discussion on: GatsbyJs - Add environment variables

Collapse
 
andybrownlie profile image
thunk

Hi Kapil

Thanks for this, sort of got this working on Windows with an env variable. However, when I try to use this env variable in my gatsby-config.js to set a value with my plugins (e.g. Google Analytics tracking ID) it doesn't work. Have you managed to get it working in this gatsby-config.js file?

Collapse
 
raevilman profile image
RD

Hi Andy,

I solved it by adding below to my gatsby-config.js

require("dotenv").config({
  path: `.env.${process.env.NODE_ENV}`,
})
Enter fullscreen mode Exit fullscreen mode

Wrote a note about it at therdnotes.com/building-a-markdown...

HIH ✌