📜  在反应应用程序中隐藏 .env 中的网址 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:55.977000             🧑  作者: Mango

代码示例1
WARNING: Do not store any secrets (such as private API keys) in your React app!

Environment variables are embedded into the build, meaning anyone can view them by inspecting your app's files.

outside our src folder create .env file and add it to gitignore
REACT_APP_WEATHER_API_KEY=123456
inside where you want to access the variable 
const API_KEY = process.env.REACT_APP_WEATHER_API_KEY;

make sure to restart the server