Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Node.js Basics (2014) Building a Command Line Application Making a GET Request with http

Christoph Walpert
Christoph Walpert
3,752 Points

Getting Unhandled error

Hi, on making the http request i get this error message, when I run my code in the console:

treehouse:~/workspace$ node app.js                                                                                               
events.js:160                                                                                                                    
      throw er; // Unhandled 'error' event                                                                                       
      ^                                                                                                                          

Error: getaddrinfo ENOTFOUND teamtreahouse.com teamtreahouse.com:80                                                              
    at errnoException (dns.js:28:10)                                                                                             
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:79:26)  

And this is my code:

// Problem: We need a simple way to look at a user's badge count and JavaScript points

// Solution: Use Node.je to connect to Treehouse's API to get the Profile information to print out
var http = require("http");
var username = "chalkers"

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 

var request = http.get("http://teamtreahouse.com/"+ username +".json", function(response) {
  console.dir(response);
});  

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

Thanks for the help :)

1 Answer

Tommaso Poletti
Tommaso Poletti
5,205 Points

For Get the 200 in console you must change this two things:

the http variables

var https = require("https");

and in the request:

var request = http.get("https://teamtreehouse.com/" + username + ".json", function(response) {

  console.log(response.statusCode);
});

Because the site is now on https ;)