How to chain middlewares in Express.js
Nội Dung Chính
Arguments
Middlewares take three arguments:
req
: the request objectres
: the response objectnext
:next
is a function that passes execution to the next middleware when it is done.
Middlewares are used inside the app.use()
or app.METHOD()
functions, where METHOD
refers to the HTTP
verbs GET
, POST
, PUT
, DELETE
, and more.
Chaining middlewares
Middlewares can be chained. We can use more than one middleware on an Express app instance, which means that we can use more than one middleware inside app.use()
or app.METHOD()
. We use a comma (,
) to separate them.