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 Express Basics (2015) Getting Started with Express Your First Express App

Leigh Maher
Leigh Maher
21,830 Points

Where do we pass the response and request arguments into the callback function?

The get method takes 2 parameters: the route and the function. The function itself takes 2 parameters: response and request.

Where do we pass the arguments into this callback function? Are these arguments a part of the get method?

1 Answer

akak
akak
29,445 Points

Yes, the GET method after doing it's thing has internally those two variables (probably not named that way, but that's not important) and is passing them into a callback function. In fact GET just "runs" the callback function. That's how callback works. A simplified example:

function get (URL, callback) {

   var request;
   var response;

    // internal stuff responsible for populating those variables.

    // after all is done
    callback(request, response);
}

So after GET does it thing it has those two variables, and is running your callback function, passing them as arguments.

Leigh Maher
Leigh Maher
21,830 Points

Perfect. Thanks Akak.