loading...

Discussion on: How Can I Access Environment Variables in My Static Website?

Collapse
alexlsalt profile image
Alex Morton Author

Yes! That's it. But I don't want the key to be able to be seen in the project files (on GitHub for example). Does that make sense?

Collapse
mellen profile image
Matt Ellen

Yes. 👍

I'm a bit out of the loop on web dev with APIs, but if you put the key in the JS file, doesn't that mean everyone who visits your website will have access to your API key (by reading the JS file)?

If that is the case, then to keep it only on your server you'll need some server side script to make the call to the API and then put the result into the site, either as the site is rendered or via fetch, XHR or similar.

I will admit I don't know react at all, and I don't know node.js very well, but it is used as a server side script runner, so it should have the capability to do the work you need.