Web应用中间件理解

Web application middleware understanding

我是 node.js 的初学者,我正在尝试构建我的第一个 Web 应用程序。 但是我想从一开始就获得良好的实践。

所以我学习了一些指南来组织我的代码。 我继续使用我很了解的 MVC 模式。但是在我阅读的指南中,除了模型、视图和控制器部分,还有一个中间件部分。 我看不出中间件和控制器之间的区别 这是指南:http://www.terlici.com/2014/08/25/best-practices-express-structure.html

有人能准确解释一下使用中间件的目的是什么,以及中间件和控制器之间的区别吗?

提前致谢。

您提供的 link 说得最好:

The purpose of a middleware is to extract a common controller code, which should be executed on multiple requests and usually modifies the request and/or the response objects.

所以基本上,如果您有在控制器之间共享的功能,您可以将它放在中间件中。

解释得更详细了here