javascript - 是什么让 Express 属于框架而不是 Web 服务器的范畴?

标签 javascript express frameworks webserver

我很惊讶地发现它被称为框架。在 MEAN 堆栈缩写中,它取代了 Web 服务器“(A)pache”和“(I)IS”(例如 LAMP、WISP 等),它们都是 Web 服务器 - 但这并不是不称其为框架的原因,但谁能解释一下为什么它属于框架阵营?

最佳答案

首先,Express 不是网络服务器。它没有自己的网络服务器代码。 它可以为您创建一个标准的 Node.js http 服务器(当您执行 app.listen() 时),或者您可以创建自己的 httphttps 服务器并将其作为设置的一部分传递给 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/

相关文章:

javascript - JS 跨浏览器不一致/差异

javascript - 否则进行 Angular 路由

javascript - 如何访问和更改 keystone.js 登录页面?

macos - Mac App Store 中的第三方框架

javascript - 单击按钮后如何在 jquery 中弹出使用 window.open 的模式对话框

javascript - 搜索关键字数组以查看是否有任何字符与用户输入匹配

javascript - 如何在向上滚动时禁用滚动触发器 gsap ScrollTrigger?

html - 使用每行具有多个元素的 Jade/Express.js 渲染表格

Java 时间节省器

swift - 我可以使用swift编程语言来开发框架吗?