Update index.md (#31780)
This commit is contained in:
committed by
Randell Dawson
parent
374f074f0f
commit
3c0c15c189
@ -211,7 +211,7 @@ If we now start the server from command line using `node index.js` and try visit
|
||||
|
||||
Middleware functions are those functions that have access to the request object (`req`), the response object (`res`), and the `next` function in the application’s request-response cycle. The objective of these functions is to modify request and response objects for tasks like parsing request bodies, adding response headers, make other changes to request-response cycle, end the request-response cycle and call the next middleware function.
|
||||
|
||||
The `next` function is a function in the Express router which is used to execute the other middleware functions succeeding the current middleware. If a middleware function does include `next()` that means the request-response cycle is ended there. The name of the function `next()` here is totally arbitary and you can name it whatever you like but is important to stick to best practices and try to follow a few conventions, especially if you are working with other developers.
|
||||
The `next` function is a function in the Express router which is used to execute the other middleware functions succeeding the current middleware. It executes the next middleware function sitting in the middleware stack. If a middleware function does not include `next()` that means the request-response cycle is ended there. The name of the function `next()` here is totally arbitary and you can name it whatever you like but is important to stick to best practices and try to follow a few conventions, especially if you are working with other developers. For example , in passport strategies you will find `done()` function which is another name for the succeeding middleware.
|
||||
|
||||
Also, when writing a custom middleware do not forget to add `next()` function to it. If you do not mention `next()` the request-response cycle will hang in middle of nowhere and you servr might cause the client to time out.
|
||||
|
||||
|
Reference in New Issue
Block a user