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

Unexpected end of input

So this hasn't reaaly worked yet from example code

var https = require("https");
var username = "robohat";


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

var request = https.get("https://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.message);

  response.on("data", function (chunk) {
    body += chunk;
  });
  response.on("end", function(){
    consol.log(body);

  });

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

1 Answer

Steven Parker
Steven Parker
229,657 Points

It was tricky reconstructing this because your blockquote marks were not on separate lines, but I noticed:

  • your ...on("error"... function is missing a closing brace and parenthesis (causing "end of input" error)
  • you also have two references to response, but it is not defined

I'm curious, were you intending to blockquote your JavaScript code as Swift on purpose?