I made a weather app in create-react-app. How do I hide the API key so that I can commit to GitHub?
Right now the key is in App.js: const API_KEY = "123456";
Unfortunately, keeping any key in your React client, even if you are using gitignore and an .env
file, is not secure. As pointed out by @ClaudiuCreanga, React environment variables are embedded in the build and are publicly accessible.
You should really only save API keys or secrets in your backend such as Node / Express. You can have your client send a request to your backend API, which can then make the actual API call with the API key and send the data back to your client.