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 (2014) Building a Command Line Application Getting the Response Body

Nadine Schermerhorn
Nadine Schermerhorn
2,324 Points

Having trouble with the "Getting the Response Body" video. My workspace doesn't come return the body.

My workspace isn't responding the same as the video. It doesn't appear to be going through the response.on function section since I can't console.log anything out of it. Help//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
var username = "chalkers";
var http = require("http");
function printMessage(username, badgeCount, points) {
  var message = username + "has " + badgeCount + " total badge(s) and " + points + " points in JavaScript";
  console.log(message);
}
//printMessage("Chalkers", 1000, 2000);
//Connect to the API URS (https://teamtreehouse.com/username.json)
var request = http.get("http://teamtreehouse.com/" + username + ".json", function(response) {
    console.log(response.statusCode);
    response.on('data', function(chunk) {  //Read the data
        console.log('BODY: ' + chunk);

    }); 

//Parse the data (bring the data from a string into program friendly way of interacting with it)
//Print the data
});

request.on("error", function(error) { //using on method to listen for an error event
  console.error(error.message);

});

1 Answer

Joel Kraft
STAFF
Joel Kraft
Treehouse Guest Teacher

Hi Nadine,

This is probably an issue with the api, which is now served over https instead of http. See the accepted answer to this post, and let us know if that solves it for you.