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

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

    After simplifying things, a web server can be seen as a function that takes in a request and outputs a response. So if you view a web server as a function, you could organize it into several pieces and separate them into smaller functions so that the composition of them will be the original function.

    Middlewares are the smaller functions that you can compose with others and the obvious benefit is that you can reuse them.

提交回复
热议问题