API keys and environment variables on netlify

Hi @fool! Thank you for posting this here. I am still a bit confused with all this…a caveat though, I am new to Netlify and to coding… so bear with me.

I have set my .env.development file in my gatsbyJS site so that I can store my API_KEY and APP_ID in order to not expose them when I commit to git. That was perfectly and I am able to ping and use my API endpoint, however I want it to work when my site is live and for same reason, I am not able to do that.

I have also set my environment variables in Netlify UI so that I can have access them at build time (I guess?), on my files I am still using process.env.API_KEY in order to used them, but for same reason I am not able to get to them. How can I inject the variables from NETLIFY UI into my client-side code?

For same reason I am not able to achieve this.

Any guidance would be very much appreciated.


@perry, could you help me with this one? Super thank you.

@tiagofsanchez in order to get en vars in to your client side code when you use Gatsby, you need to prefix the variable names with GATSBY_. This is in the official Gatsby docs.

Also, please make sure you don’t commit your .env.development file to your git repo!

1 Like

Hi @futuregerald thank you very much for that! It worked.
Cheers to you.

1 Like