NodeJs | Express | Parcel | SCSS
Design comparison
Solution retrospective
In this challenge I created a small express app in order to hide the secret API_KEY from IP Geolocation API.
That's my first time using environment variables on Netlify, then I was not sure how to access these variables on development context. I ended up creating a .env file and used the dotenv library for development. It worked. But, I think it's better I do some more research about this topic. But if someone knows, I will be very glad to hear if I did the right thing.
Community feedback
- @DavidMorgadePosted over 2 years ago
Hello Vander, congrats on finishing this challenge! pretty good job with the API_KEY hide on the backend!
You App seems to work good but I can enter any type of value and it keeps loading to infinity, maybe you can add some validation to your input so it only gets valid ip's or domains, you can use a simple regular expression on your function that executes the code, for example this one:
const ipRegex = '^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\.(?!$)|$)){4}$'
Also would recommend you to handle the error in the html or maybe displaying an
alert()
so a normal user can see when the app is failing and why, you can use atry catch
block in yourfetch
function and catch the error, and the display the error if it fails, don't know how it works with axios tho, I have always used the fetch function.Hope my feedback helps you!, Good job!
Marked as helpful0@vandermsPosted over 2 years ago@DavidMorgade , hi David thanks for your comment.
Indeed, I didn't test for user invalid input. But instead of writing a regex pattern, I would recommend a library like ip-regex https://www.npmjs.com/package/ip-regex. Because it works with both IPv4 and IPv6.
In axios is about the same thing. In async functions you can use the try-catch pattern, or use the .then .catch pattern with promises.
Thanks!
1
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