Monday, January 30, 2023

93/365: React Environment Variables

 My review management app requires things like a business's email so they can be sent customer feedback. Hard coding this into the app is bad practice. Instead, I put all this information in a .env file. From there, I can reference the data in my components with the process.env object. There's two important things to keep in mind: Firstly, all the variable names must begin with REACT_APP. My Express server, for example, I named REACT_APP_SERVER and called it by referencing process.env.REACT_APP_SERVER. Second, you need to be careful how your environment files interact with version control. You don't want to push your changes to GitHub and accidentally publish your API key or some private emails. The way to do this is by editing your .gitignore file. This instructs your version control system to ignore .env files for instance, so I can push my changes to GitHub while keeping my local variables safe on my PC. 

No comments:

Post a Comment

190: Sablier

 The CodeHawks platform has an upcoming audit on the Sablier protocol, so I decided to read through the docs and familiarize myself with the...