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

This code doesn't seem to work for me

Still getting a long error message of 10-12 lines instead of error message

//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 http = require("https");
var username = "ashishmehra23";

function printMessage(username, badgeCount, points) {
  var 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)
var request = http.get("http://teamtreehouse.com/" + username + ".json", function(response){
  console.log(response.statusCode);
  //Read the data
  //Parse the data
  //Print the data
});

request.on("error",function(error){
   console.error(error);
})

1 Answer

Hello,

It would be helpful to see the given error that is being out printed however I have a guess as to what may be the problem. In Node, there are 2 different types of http server types available. Your code is using the more secure https server, therefore when you go to make the call on line 15, use https instead of http

...("https://teamtreehouse.com/" + username + ".json")