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

前端 未结 9 1306
小蘑菇
小蘑菇 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:16

    Middlewares are functions executed in the middle after the input/source then produces an output which could be the final output or could be used by the next middleware until the cycle is complete.

    It is like a product that goes through an assembly line where it gets modified as it moves along until it gets completed, evaluated or gets rejected.

    A middleware expects some value to work on (i.e. parameter values) and based on some logic the middleware will call or not call the next middleware or send a response back to the client.

    If you can't still grasp the middleware concept, it is in a way similar to the Decorator or Chain of command patterns.

提交回复
热议问题