for development I have an API key stored in env.local which works fine.
for deployment, I have set an env variable for the API through Netlify’s build and deploy settings. When I try to access it in the get request, it’s returned as undefined.
when I console log process.env in development, I, the key shows up, but when It’s logged in the deployed site, the variable I made in the build and deploy settings are not there at all in process.env, so I guess that’s why it’s giving me undefined.
So any idea why I’m not able to access the environment variable? thanks!
In development the api is taken from env.local. I thought the enviroment variable through Netlify would be usable regardless of whatever is in gitignor, since it is coming from Netlify? (i’m new to this stuff :s)
Yes, that’s exactly what I’ve done and that’s the problem I’m having. I have set the variable for my api through Netlify App[YOUR SITE NAME]/settings/deploys#environment but it returns undefined when It’s accessed in the app.
So - the article Perry first linked you to is very specific: process.env.WHATEVER is not going to be defined at browse time. You’ll have to interpolate that value, during build, with what you want, unless you have a very specific use case like a variable of the special sort that gatsby/react/etc provide that are mentioned at the end of the article.
My question to you would be “how are you USING that variable, during build, to put its value into your files?” process.env.X has that value during build - but not during run - and that would be intended and explained in detail in that article