Reputation: 1337
I'm using DOTENV module, I want to hide my api key on my github repo, however Netlify needs this to build the api call. I want to create a variable that runs on build in Netlify, yet still works in my development version.
In my code I use this:
let unsplashApiKey = process.env.REACT_APP_UNSPLASH;
Which links to an .env in the root, this works in my dev localhost, I can ignore this with gitignore, but then Netlify needs this .env to run its build, because it builds directly from the repo.
I've seen in DEPLOY SETTINGS in Netlify this option: "Environment Variables", it lets me place name and key, seems to be what I need. How then do I make this varible work for my api inside my code?
Upvotes: 1
Views: 523
Reputation: 1337
all I had to do was call the environmental variable this: REACT_APP_UNSPLASH
Due to my code being like this:
let unsplashApiKey = process.env.REACT_APP_UNSPLASH;
I was using the unsplashApiKey
in the Netlify variable, which was not working. Now I have been able to hide the .env file in my repo, yet have it in my local, therefore hiding the api key from posible nasty people. Happy days!
Upvotes: 1