What does middleware and app.use actually mean in Expressjs?

前端 未结 9 1320
小蘑菇
小蘑菇 2020-11-29 14:55

Almost every Express app I see has an app.use statement for middleware but I haven\'t found a clear, concise explanation of what middleware actually is and what

9条回答
  •  庸人自扰
    2020-11-29 15:06

    Middleware is a subset of chained functions called by the Express js routing layer before the user-defined handler is invoked. Middleware functions have full access to the request and response objects and can modify either of them.

    The middleware chain is always called in the exact order in which it has been defined, so it is vital for you to know exactly what a specific piece of middleware is doing.
    Once a middleware function finishes, it calls the next function in the chain by invoking its next argument as function.
    After the complete chain gets executed,the user request handler is called.

提交回复
热议问题