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 Building a Command Line Application Making a GET Request with https

Madeline Yao
seal-mask
.a{fill-rule:evenodd;}techdegree
Madeline Yao
Full Stack JavaScript Techdegree Student 9,611 Points

Why we need to require module in order to gain information from API?

// Problem: We need a simple way to look at a user's badge count and JavaScript points // Solution: Use Node.js to connect to Treehouse's API to get profile information to print out

//Require https module const https = require('https'); const username = "chalkers";

//Function to print message to console function printMessage(username, badgeCount, points) { const message = ${username} has ${badgeCount} total badge(s) and ${points} points in JavaScript; console.log(message); }

// Connect to the API URL (https://teamtreehouse.com/username.json) const request = https.get(https://teamtreehouse.com/${username}.json, response => {

                      console.log(response.statusCode);

                      // Read the data
                      // Parse the data
                      // Print the data

                      });

In the video tutorial, I notice that when you do not require https, you cannot get information from API. I wonder why that happens. Could anyone please explain to me about that and the importance of the module? Thank you!

3 Answers

Steven Parker
Steven Parker
231,261 Points

The "https" module contains the code for the "https.get" method that the code is using to perform the request.

Routine Poutine
Routine Poutine
26,050 Points

Is a module another word for snippet?

Steven Parker
Steven Parker
231,261 Points

A "module" would be less than a whole program, but it would typically be in it's own file, and contain one or more complete functions and /or object definitions.

A "snippet" could be any small piece of code, perhaps only part of a function.

Routine Poutine
Routine Poutine
26,050 Points

Steven, That’s very helpful, thanks!

So then wouldn't a "library" be the same as a "module"? Or is a library essentially just a really big module?

Steven Parker
Steven Parker
231,261 Points

Sure, a module could be described as a "library".