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 Getting the Response Body

Abi Houghton
Abi Houghton
111 Points

node.js

my code is exactly the same to the guy in the video but nothing is working, it brings up a blank line in the command prompt then back to the workspace this is my code

//problem: we need a simple way to look at a users badge count and javascript points
//solution: use node.js to cnnect to treehouse api to get 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 (http://teamtreehouse.com/username.json)
var request = http.get("http://teamtreehouse.com/" + username + ".json", function(response){
  var body = "";
    // read data 
  response.on('data',function (chunk) {
body += chunk;
});
  response.on('end', function(){
    console.log(body);
  });
  response.on('end', function(){
    console.log(body);
  });
//parse the data (read from string)
//print the data out
});

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

can anyone help me

Lojnita Florin Octavian
Lojnita Florin Octavian
Courses Plus Student 176 Points

change

var http = require("http");

to

var https = require("https"); 

also change the treehouse http method and link to match https

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

Treehouse moved the files on HTTPS and this tutorial is getting kinda bad.

[MOD: added formatting -cf]