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

[About Node js] Although I've watched the video, still can't figure out what these code doing....

I know something(a few lines of code) but not sure if it's correct, please help.

const https = require("https");
// I know this line is for "loading the http module"

const request = https.get("https://teamtreehouse.com/chalkers.json", response => {
//And the url is where I can get the data.
//And there's a function named "response"

//below ... I don't understand.
    let responseBody = "";

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

    });

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

});

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

1 Answer

HIDAYATULLAH ARGHANDABI
HIDAYATULLAH ARGHANDABI
21,058 Points

Dear TSENG FUCHUN, After the script run or specifically when the you request the the app it will return a response that response is render in the response.on method.