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

Daron Anderson
Daron Anderson
1,965 Points

Having trouble modifying the call back Can anyone offer suggestions?

Code attached

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

    response.on("data", dataChunk => {
// CORRECT ANSWER
        responseBody += dataChunk.toString();

    });

    response.on("data", () => {
        console.log(responseBody);
// CUT OUT THIS IMPOSTER FIRST LINE vv
        responseBody += dataChunk();
    });

});

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

1 Answer

Daron Anderson
Daron Anderson
1,965 Points

This was another false alarm I had solved, I feel as though the question was not being specific enough, It asked modify the data callback to concatenate the stream of data to the responseBody.. Not to read in the data and then convert it to a string. SMH.