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 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
231,275 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
231,275 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 => {});