我很惊讶地发现它被称为框架。在 MEAN 堆栈缩写中,它取代了 Web 服务器“(A)pache”和“(I)IS”(例如 LAMP、WISP 等),它们都是 Web 服务器 - 但这并不是不称其为框架的原因,但谁能解释一下为什么它属于框架阵营?
最佳答案
首先,Express 不是网络服务器。它没有自己的网络服务器代码。
它可以为您创建一个标准的 Node.js http
服务器(当您执行 app.listen()
时),或者您可以创建自己的 http
或 https
服务器并将其作为设置的一部分传递给 Express。
相反,它是一个“网络服务器之上的框架”。它提供了用于定义路由和中间件、错误处理程序和模板渲染器(以及其他东西)的通用机制。
作为一个迹象,有大量的 NPM 插件可以通过 Express 中间件或 Express 路由机制或渲染 API 插入到您的 Web 服务器中(它们以标准方式插入到框架中)。在我看来,这种通过标准机制插入的方式使其成为一个框架。
因此,Apache 实际上是一个 Web 服务器本身,而 Express 是一个运行在已内置于 Node.js 中的 Web 服务器之上的层。
它当然不是一个通用的编程框架,而是一种非常特定类型的 Web 服务器框架。
摘自维基百科的“软件框架”页面:
In computer programming, a software framework is an abstraction in which software providing generic functionality can be selectively changed by additional user-written code, thus providing application-specific software. A software framework provides a standard way to build and deploy applications. A software framework is a universal, reusable software environment that provides particular functionality as part of a larger software platform to facilitate development of software applications, products and solutions
根据此定义评估 Express,它会获得所有这些元素的复选标记:
✔ Abstraction providing generic functionality
✔ can be selectively changed by additional user-written code
✔ thus providing application-specific software
✔ A software framework provides a standard way to build and deploy applications
✔ A software framework is a universal, reusable software environment that provides particular functionality as part of a larger software platform to facilitate development of software applications, products and solutions
本例中的“应用程序”是一个 Node.js Web 服务器。
关于javascript - 是什么让 Express 属于框架而不是 Web 服务器的范畴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49502932/