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 2017 Building a Command Line Application Getting the Response Body

See the console.log(responseBody); in that callback around line 10? Fix the listener so that the

It has been a long day and the response is "Unexpected )" And I do not see that error. Cant anybody recommend a suggestion?

Thanks Joe

app.js
    const https = require("https");
    const request = https.get("https://teamtreehouse.com/chalkers.json", function(response) {
    let responseBody = "";
    });

    response.on("data", function(dataChunk) {
      responseBody += dataChunk; });
    });

    response.on("end", (function) () {
        console.log(responseBody);
    });

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

3 Answers

This course is terrible

I wish Treehouse would redo this course with Guil. His courses are so clear and well put together.

Laura Sweet
Laura Sweet
2,782 Points

Agreed! Very hard to follow.

The explanations are good, but this course needs more practice problems. If you don't apply the concepts enough, all the information will just go in one ear and out the other.

If you're looking for extra practice, The Odin Project has a course on Node that's free.

Yeah pretty much every course with Chalkers really makes me hesitate.

Marlene Guzman
Marlene Guzman
9,231 Points

so they want you to add "end" to the response function.

 response.on("end", () => {
        console.log(responseBody);
    });

so your completed code will look like this.

const https = require("https");
const request = https.get("https://teamtreehouse.com/chalkers.json", response => {
    let responseBody = "";

    response.on("data", dataChunk => {
        responseBody += dataChunk;
    });

    response.on("end", () => {
        console.log(responseBody);
    });

});

request.on("error", error => {
    console.error(error.message);
});
andren
andren
28,558 Points

I notice two syntax errors in your code:

The first one is in this line:

responseBody += dataChunk; });

The callback and function is closed on the line below so the last couple of characters "});" do not belong on that line.

The second is in this line:

response.on("end", (function) () {

The parenthesis wrapping the function keyword is invalid, they should not be there.

If you remove the unnecessary characters and the parenthesis I pointed out above then your code should work.