JavaScript Node.js Basics Create a Command Line Weather Application Retrieving Data - Solution

Kristian Woods
Kristian Woods
22,208 Points

I don't understand the use of the api.json file

So, in the video, he shows us a file that contains an object with the key "key" and value "<Enter your API key>" - I have two questions:

1) He mentions hiding the API from people via GitHub. How and why does his method accomplish this?

2) In the URL in the get() - He uses "${api.key}".... wouldn't this return "<Enter your API key>" into the URL?

Thanks

Kristian

1 Answer

andren
andren
28,336 Points

1) He mentions hiding the API from people via GitHub. How and why does his method accomplish this?

When you upload a project to github you can mark specific files as ignored. Which means that they won't be uploaded. By storing the API key in a specific file and then ignoring that file he can upload the project to github without anybody gaining access to the key. If the key was used directly in his app.js file then anybody looking at his github project would be able to see the key.

2) In the URL in the get() - He uses "${api.key}".... wouldn't this return "<Enter your API key>" into the URL?

Yes, but "<Enter your API key>" is a placeholder, he didn't want to show an actual API key in the video but when following along with this video you are supposed to paste in your own API key, and store it in the api.key property.

Kristian Woods
Kristian Woods
22,208 Points

Great answer, thanks, andren!