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

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 (https://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]