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!
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
Philip Bradbury33,368 Points
Why does the call back function run when not called only assigned?
Im viewing this video a little confused. The Https.get() is assigned to request. request is not called anywhere in the app.js it in only assigned. With this been the case why does the callback execute the console.dir() inside the callback? Shouldn't this only run when the request is called?
Steven Parker227,141 Points
The request variable is not a function.
When you say "request is not called anywhere..." it sounds like you are expecting request to contain a reference to a function, but it does not. In the assignment of request,
https.get() is called, and it is the result of that call (and not the method itself) that is stored in request. The result is an http.ClientRequest object.
Just calling the
https.get() method sets the callback to run when the request completes. So there's no need to make use of request just for this to happen.