Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

29,444 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.