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

daniwao
daniwao
13,125 Points

Response BODY not found, 404

I tried getting the BODY + chunk piece back. What is funny is that I think that the API for teamtreehouse is not letting me access my username. I switched my username to chalkers and it worked. But when I put back in my username 'daniwao' it didn't work. I know that this is my username because I then tried teamtreehouse.com/daniwao.json and it worked.

Can someone help me out with this question. Here's my code below.

var http = require("http");
var username = "daniwao";

function printMessage(username, badgeCount, points){
    var message = username + " has " + badgeCount + " total badges and " + points + " points in Javascript";
    console.log(message);
}

var request = http.get("http://teamtreehouse.com/" + username + ".json", function(response){
    var body = "";
    console.log(response.statusCode); 
    response.on('data', function(chunk) {
     body += chunk;
    console.log('BODY: ' + chunk)
  });

  response.on('end', function(){
    var profile = JSON.parse(body);
    console.dir(profile);
  })
});

request.on("error", function(e){ 
    console.error(e.message);
})
daniwao
daniwao
13,125 Points

Andrew Chalkley , I'd really appreciate if you could take a look at this interesting issue I'm having. I can use your username and I've tested it out with other usernames, just by guessing by looking at the Forum, but I can't use my username. Is there a timeout issue?

1 Answer

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Your privacy settings prevent your profile from being visible to the public. So if you are logged in you can see it. Log out and go to teamtreehouse.com/daniwao.json and see it's not found :)