Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

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,558 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.

Great answer, thanks, andren!