Design comparison
SolutionDesign
Solution retrospective
Any feedback is welcome! How do you store and use your sensitive variables, like API keys, in your projects?
Community feedback
- @ErayBarslanPosted about 2 years ago
Hey there, you can achieve it by using
dotenv
package and by following these steps:npm i dotenv
to download the package- Open a file named .env and store your sensitive variables like:
API_KEY="secret-key" PASSWORD="675jfl485"
- In your JS file you can call the variable like:
import dotenv from 'dotenv'; dotenv.config(); /* OR */ require('dotenv').config(); fetch(`https://geo.ipify.org/api/v2/country,city?apiKey=${process.env.API_KEY}&ipAddress=${ipAddress}`)
- Lastly you should create a
.gitignore
file and add.env
so it won't be shared in the repo. These should do the trick for you.
A little suggestion I can give regarding accessibility, if you use a button with no text in it you can use aria-label like:
<button class="submit-btn" aria-label="submit button"> <img src="./images/icon-arrow.svg" alt="arrow icon" aria-hidden="true"> </button>
Other than this little thingy, you have a great solution! Happy coding :)
Marked as helpful1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord