JavaScript Node.js Basics Building a Command Line Application Getting the Response Body

Need help with getting the response body challenge

I've tried everything I can think of to the code to work but after review the video and documentation, I am still unable to get it to work. Please...help...

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

    response.on("data", dataChunk => {

    });

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

});

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

1 Answer

Darryl Mah
Darryl Mah
5,476 Points

Aloha,

In this challenge you’ll want to concatenate the “responseBody” with “dataChunk”. Since they’re both strings you’ll can use the “+” or “+=“ to combine the two. You want to do this on the response.on function with the “dataChunk” callback

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

Or

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

Hope this helps!

Thank you so much!