Can't access environment variables

What did you end up doing? I still cannot get mine to work. I am using create-react-app.

Here’s a snippet of my code where I am able to successfully access the variable on my local environment:

const url = https://www.omdbapi.com/?s=${searchValue}&apikey=${process.env.REACT_APP_OMDB_API_KEY}`;`

I have a .env file in my React project that is part of my .gitignore file:

REACT_APP_OMDB_API_KEY = 123456

This works fine locally. As soon as I push my code to GitHub, which integrates with Netlify, the API key is undefined. I tried adding the variable in the GUI but that didn’t work either:

I have seen other conversations about this issue but I haven’t exactly found a solution. It’s confusing and I don’t know why it has to be this complicated. This key is not public but it’s not exactly private either. It’s just an API for a movie database, so nobody’s gaining any real value from this. If I have to keep it exposed then I will. It’s only a portfolio project, although I’d prefer that people notice that I have security in mind…

1 Like