Node.js FAQ: Top Questions
14. What is middleware in Express.js?
Middleware
in Express.js are functions that execute during the request-response cycle, with access to
req
,
res
, and
next
, used for tasks like logging, authentication, or parsing.
- Types: Application-level, router-level, error-handling, built-in, third-party.
-
Execution:
Runs in order, calls
nextto proceed. -
Examples:
express.json(), custom logging middleware. - Use Case: Request preprocessing, response modification.
