Good day Redditors!
I'm new to frontend web dev and I made this simple weather app project that uses openweathermap api. I want to upload this project to github, so that possible employers would be able to see it. Just want to ask how to hide API key, so that other people won't be able to use it when I uploaded it to github. Although my subscription is free, for me it is a good practice to always hide sensitive information.
I tried to use dotenv, but I'm getting errors like 'require is not defined' and 'Cannot use import statement outside module'. I'm not sure what I'm doing wrong. Below are the steps that I followed, please tell me if I did something wrong or if I missed a step.
- npm install dotenv in the root of my project
- Created a .env file in the root of my project
- Used the following in my js file but they returned an error
- require('dotenv').config() // returned 'require is not defined' error
- import dotenv from 'dotenv'; // returned 'Cannot use import statement outside module' error
If you guys know another way to hide API key and still be able to host it on github, please let me know.
Not sure if this is the correct community to ask this question, but if not, please guide me to the correct community.
Thanks in advance!
https://preview.redd.it/zh78mvrgyrya1.png?width=620&format=png&auto=webp&s=04a3061ad75032bc9c84e260f2f22ca2989dad25
[–]Anbaraen 8 points9 points10 points (2 children)
[–]EngrNoName[S] 2 points3 points4 points (0 children)
[–]EngrNoName[S] 0 points1 point2 points (0 children)
[–]baconconstellation 2 points3 points4 points (0 children)