0 votes
in JavaScript by
When you use app.use('/some_route', myCallBack())?

1 Answer

0 votes
by

When you use app.use('/some_route', myCallBack()). Express will listen for requests for that route, and when it’s hit, it will call the function you provided and give it three parameters: request, response and next (actually four but let keep things simple for now).

The params are the request, response and next. No matter what you call them or not, express will in its internal workings call the function you provided like this:

function myCallback(requestObject, responseObject, nextMiddleware) { }

The requestObject: contains information about the HTTP request. You can access the request headers, full url, caller IP address etc within the requestObject.

The responseObject: is used to handle the requestObject. The responseObject represents the HTTP response that an Express app sends when it gets an HTTP request.

Related questions

0 votes
asked Oct 8, 2023 in JavaScript by JackTerrance
0 votes
asked Feb 20 in JavaScript by DavidAnderson
...