JavaScript Node.js Basics Building a Command Line Application Making a GET Request with https

Damian McCarthy
Damian McCarthy
3,656 Points

I dont understand this one at all, how do I put this into a callback function.

I am not sure how to do this, I am not sure how to place this in a callback function.

app.js
const https = require('https');
https.get('https://teamtreehouse.com/chalkers.json')

1 Answer

Steven Parker
Steven Parker
167,902 Points

You may have misunderstood the instructions. They say, "Now, in the https.get() call pass in an anonymous function as a callback with the parameter of response. This function is the second parameter in the get call."

So you're not being asked to put the current code into a callback function, they want you to create a callback function as an additional parameter of the call:

https.get('https://teamtreehouse.com/chalkers.json', /* your new callback goes here */)
Damian McCarthy
Damian McCarthy
3,656 Points

That is what I initially thought, and I attempted this :

const https = require('https');
https.get('https://teamtreehouse.com/chalkers.json'), response => {
};

but that comes back as that there is no https.get request.

Steven Parker
Steven Parker
167,902 Points

You nearly had it there. You just have the closing parenthesis in the wrong place:

https.get('https://teamtreehouse.com/chalkers.json'), response => {};
// move ) to enclose both arguments                ^---------------v
https.get('https://teamtreehouse.com/chalkers.json', response => {});