我们可以说 node.js 是一个 Web 服务器吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9462356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can we say node.js is a web server?
提问by Kit Ho
I found that I am confusing between web framework and web server.
我发现我在 Web 框架和 Web 服务器之间感到困惑。
Apache is a web server.
Apache is a web server.
Tornado is a web server written in Python.
Tornado is a web server written in Python.
Nginx is a web server written in C
Nginx is a web server written in C
Zend is a web framework in php
Zend is a web framework in php
Flask/Bottle is a web framework in Python
Flask/Bottle is a web framework in Python
RoR is a web framework written in Ruby
RoR is a web framework written in Ruby
Express is a web framework written in JS under Node.JS
Express is a web framework written in JS under Node.JS
Can we say node.js is a web server??? I am so confused between web server/ framework.
我们可以说 node.js 是一个 Web 服务器吗???我在网络服务器/框架之间很困惑。
If somehow node.js is kind of webserver, not webframework (Express does), why do we need to put the whole node.js on top of Nginx server in useful practice?? Question on SO
如果不知何故 node.js 是一种网络服务器,而不是网络框架(Express 是),为什么我们需要在有用的实践中将整个 node.js 放在 Nginx 服务器之上?? 关于 SO 的问题
Who can help???
谁能帮忙???
Kit
成套工具
采纳答案by Alfred
Web server
网络服务器
Web server can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that can be accessed through the Internet.1
The primary function of a web server is to deliver web pages on the request to clients. This means delivery of HTML documents and any additional content that may be included by a document, such as images, style sheets and scripts.
Web 服务器可以指帮助提供可通过 Internet 访问的内容的硬件(计算机)或软件(计算机应用程序)。1
Web 服务器的主要功能是根据请求向客户端传送网页。这意味着交付 HTML 文档和文档中可能包含的任何附加内容,例如图像、样式表和脚本。
A web server is the basic to delivering requests/pagess to the clients/user on the internet
Web 服务器是向 Internet 上的客户端/用户提供请求/页面的基础
Web framework
网络框架
A web application framework is a software framework that is designed to support the development of dynamic websites, web applications and web services. The framework aims to alleviate the overhead associated with common activities performed in Web development. For example, many frameworks provide libraries for database access, templating frameworks and session management, and they often promote code reuse.
Web 应用程序框架是一种软件框架,旨在支持动态网站、Web 应用程序和 Web 服务的开发。该框架旨在减轻与 Web 开发中执行的常见活动相关的开销。例如,许多框架提供用于数据库访问、模板框架和会话管理的库,并且它们经常促进代码重用。
A web framework uses a webserver to deliver the requests to client, but it is not the web server.
Web 框架使用 Web 服务器将请求传递给客户端,但它不是 Web 服务器。
Node.js
节点.js
Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
Node.js 是一个基于 Chrome 的 JavaScript 运行时构建的平台,用于轻松构建快速、可扩展的网络应用程序。Node.js 使用事件驱动的非阻塞 I/O 模型,使其轻量级和高效,非常适合跨分布式设备运行的数据密集型实时应用程序。
But then again you can also create CLI apps so I think you should see it more as a platform to write javascript programs to run on your server(computer) using Javascriptprogramming languageinstead of just in the browser as in the beginning. I think you could see it as Javascript++??
但话又说回来,您也可以创建 CLI 应用程序,所以我认为您应该将其更多地视为一个平台,可以使用Javascript编程语言编写 javascript 程序以在您的服务器(计算机)上运行,而不是像开始时那样仅在浏览器中运行。我想你可以把它看成Javascript++??
You can also write web server with node.js as you can see on the front page of node.js. In the beginning Ryan said you could put Nginxin front of node.js because of the stabilty of the project. The project was and still is pretty young. Nginx is a proven web server that will keep on running while node.js can crash. Then again a lot of user just use node.js for that.
您还可以使用 node.js 编写 Web 服务器,如 node.js 的首页所示。一开始 Ryan 说你可以把Nginx放在 node.js 前面,因为项目的稳定性。该项目过去和现在都很年轻。Nginx 是经过验证的 Web 服务器,它会在 node.js 崩溃时继续运行。然后很多用户只是为此使用 node.js。
回答by ezpresso
I would say Node.jsis a Runtime Environmentor a Runtime Engine.
Probably the best definition I have found so far comes from an article by Rob Gravelle entitled "An Intro to Node.js":
到目前为止,我找到的最好的定义可能来自 Rob Gravelle 题为“An Intro to Node.js”的文章:
Node.js is part runtime environment and part library for building network applications using server-side JavaScript. It uses Chrome's JavaScript runtime engine to execute JS code directly without the need for the browser sandbox.
Node.js 是部分运行时环境和部分库,用于使用服务器端 JavaScript 构建网络应用程序。它使用 Chrome 的 JavaScript 运行时引擎直接执行 JS 代码,无需浏览器沙箱。
Also the PCMAG.COM Encyclopedia provides the following definitionof "runtime engine":
PCMAG.COM 百科全书还提供了“运行时引擎”的以下定义:
Software that certain applications depend on to run in the computer. The runtime engine must be running in the computer in order for the application to execute. It provides common routines and functions that the applications require, and it typically converts the program, which is in an interim, intermediate language, into machine language.
某些应用程序依赖于在计算机中运行的软件。运行时引擎必须在计算机中运行才能执行应用程序。它提供应用程序所需的通用例程和功能,并且通常将使用中间语言的程序转换为机器语言。
Also the Wikipedia articleentitled "Run-time system" declares:
题为“运行时系统”的维基百科文章也声明:
A run-time system (also called runtime system, runtime environment, or just runtime) implements the basic behavior of a computer language, whether the language is a compiled language, interpreted language, embedded domain-specific language, or is invoked via an API as is pthreads.
... A run-time system may implement behavior of tasks such as drawing text on the screen or making an Internet connection. It also typically acts as an abstraction layer that hides the complexity or variations in the services offered by the operating system.
运行时系统(也称为运行时系统、运行时环境或仅运行时)实现计算机语言的基本行为,无论该语言是编译语言、解释语言、嵌入式领域特定语言,还是通过 API 调用就像 pthreads 一样。
... 运行时系统可以实现诸如在屏幕上绘制文本或建立 Internet 连接等任务的行为。它还通常充当抽象层,隐藏操作系统提供的服务的复杂性或变化。
Well, are there any runtime environments (or even software platforms) like Node.js out there? I guess JRE is a good example of such an environment. Node.js and JRE - they have many in common. They all have (a kind of) virtual machine, a class library and a framework to implement many types of applications, including CLI ones.
那么,有没有像 Node.js 这样的运行时环境(甚至软件平台)?我想 JRE 是这种环境的一个很好的例子。Node.js 和 JRE - 它们有很多共同点。它们都有(一种)虚拟机、一个类库和一个框架来实现多种类型的应用程序,包括 CLI 应用程序。
So, getting back to your question, can we say that Node.js is a web server? Let's change "Node.js" for "JRE" and answer if JRE is a web server. The answer is no.
那么,回到你的问题,我们可以说 Node.js 是一个 Web 服务器吗?让我们将“Node.js”更改为“JRE”并回答 JRE 是否是 Web 服务器。答案是不。
All that we can say is that Node.js is a runtime environment which one may use to implement a web server. Well, that's my opinion.
我们只能说 Node.js 是一种运行时环境,可以用来实现 Web 服务器。嗯,这就是我的意见。
回答by Esakki Krishnan
Saying node is a webserver is like saying javacript can only run inside a browser, you can say that but it can also do a lot of other things.
说 node 是一个网络服务器就像说 javacript 只能在浏览器中运行,你可以这么说,但它也可以做很多其他的事情。
NodeJS
节点
- [Javascript runtime enviroment(Chrome v8 engine) + Node Library/APIs]
- Can create a web server, can also be described as a Application server
- [Javascript 运行环境(Chrome v8 引擎) + 节点库/APIs]
- 可以创建一个web服务器,也可以描述为一个应用服务器
Express
表达
- Web framework (uses nodejs's webserver to serve files)
- Web 框架(使用 nodejs 的 webserver 来提供文件)
Nginx
nginx
- Web server
- 网络服务器
In production most people use Nginx in front of node server as a proxy server to serve static files and other various elements like caching, routing etc.
在生产中,大多数人在节点服务器前使用 Nginx 作为代理服务器来提供静态文件和其他各种元素,如缓存、路由等。
回答by cmv
I would classify node.js as a server framework, with packages available that can make use of it as an HTTP server, or a WebSocket server, or your own custom protocol, etc.
我将 node.js 归类为服务器框架,提供的包可以将其用作 HTTP 服务器、WebSocket 服务器或您自己的自定义协议等。
The reason you might put nginx in front of your node.js server is for HTTP load balancing and reverse proxying across several machines running your server application.
您可能将 nginx 放在 node.js 服务器前面的原因是为了跨运行服务器应用程序的多台机器进行 HTTP 负载平衡和反向代理。
回答by Mad coder.
Web server is something that serves its clients through internet over protocols and Web Framework is something like which we call as compiler. It consists of all the required libraries, syntax rules, etc.
Web 服务器是通过 Internet 通过协议为其客户端提供服务的东西,而 Web 框架类似于我们称之为编译器的东西。它包含所有必需的库、语法规则等。
And node.js is a framework!!
而 node.js 是一个框架!!
回答by Trunk
How I feel your pain !
我怎么能感觉到你的痛苦!
Like many, I found it hard to get to the essence of Node.js because most people only write/talk about the part of Node that they find useful - and the part they find interesting is usually a secondary benefit of Node rather than its primary purpose. I must say that I think it's mad for people to say that Node is just a JavaScript runtime. Node's use of JavaScript - and its selection of the V8 runtime - are simply means to an end, the best tools for the problem that Node's developers wanted to solve.
像许多人一样,我发现很难了解 Node.js 的本质,因为大多数人只写/谈论他们认为有用的 Node 部分——而他们认为有趣的部分通常是 Node 的次要好处,而不是它的主要好处目的。我必须说,我认为人们说 Node 只是一个 JavaScript 运行时是很疯狂的。Node 对 JavaScript 的使用 - 以及它对 V8 运行时的选择 - 只是为了达到目的,是 Node 开发人员想要解决的问题的最佳工具。
Node's primary purpose was to make the management of user events in a web app more efficient. So Node is overwhelminglyused on the back end of a web app. Event management demands that something is listening at the server machine for these events. So a http server must be set up to route each event to its appropriate handler script. Node uses JavaScript for event handling because JavaScript has callback functions: this allows one task to be suspended until the result of a dependent task is returned. Not many other languages have this feature and those that do may not have as efficient an interpreter as Google's V8 runtime. Most web developers know JavaScript so there's no additional language learning with Node. What's more, having callback functions allows the putting of all user tasks on a single thread without having explicit blocking applied to tasks demanding access to the database or file system. And this is what leads to the superior executional efficiency of Node under heavy concurrent use - which was the primary purpose for its development.
Node 的主要目的是使 Web 应用程序中的用户事件管理更加高效。所以 Node 是压倒性的在 Web 应用程序的后端使用。事件管理要求在服务器机器上监听这些事件。因此,必须设置一个 http 服务器来将每个事件路由到其适当的处理程序脚本。Node 使用 JavaScript 进行事件处理,因为 JavaScript 具有回调函数:这允许暂停一项任务,直到返回依赖任务的结果。没有多少其他语言具有此功能,并且那些没有像 Google 的 V8 运行时那样高效的解释器。大多数 Web 开发人员都了解 JavaScript,因此无需使用 Node.js 进行额外的语言学习。更重要的是,回调函数允许将所有用户任务放在单个线程上,而无需对需要访问数据库或文件系统的任务应用显式阻塞。
To help Node users quickly write back end code, Node's developers also organized the NPM (Node Package Manager) repositary: this is an open source, user-driven set of script packages for various standard and custom functions. All Node projects allow importation of NPM packages into a project via the established npm installcommand.
为了帮助 Node 用户快速编写后端代码,Node 的开发人员还组织了 NPM(Node Package Manager)存储库:这是一个开源的、用户驱动的脚本包集,用于各种标准和自定义功能。所有 Node 项目都允许通过已建立的npm install命令将 NPM 包导入到项目中。
User requests handled via Node will be things like register/login/logout/form field validation and various database queries needed by the web app will be sent to the Node port. Other types of user request, e.g. to display another webpage, download CSS/JS/images, etc, could be sent to Node also. But these are not normally be sent to the Node port but will continue to be sent by the browser to the default port(s) on the server machine where the web server will handle them.
通过 Node 处理的用户请求将是诸如注册/登录/注销/表单字段验证之类的事情,Web 应用程序所需的各种数据库查询将被发送到 Node 端口。其他类型的用户请求,例如显示另一个网页、下载 CSS/JS/图像等,也可以发送到 Node。但是这些通常不会发送到节点端口,而是会继续由浏览器发送到服务器计算机上的默认端口,Web 服务器将在其中处理它们。
So, in practice, Node is normally a server but one that only replaces someof the functions of the web server program. Other uses of Node simply exploit one or other of its features, e.g. the V8 engine. But these are really just by-product uses of Node.
所以,在实践中,Node 通常是一个服务器,但只是替代了 web 服务器程序的一些功能。Node 的其他用途只是利用其一项或多项功能,例如 V8 引擎。但这些实际上只是 Node.js 的副产品用途。
回答by cslotty
I think the problem is that the terminology of "web server" or "web application server" is dominated by the JEE world, and products, that are not as modularized as today's Javascript world of frameworks, which in turn can be combined more or less freely.
我认为问题在于“Web 服务器”或“Web 应用程序服务器”的术语由 JEE 世界和产品主导,这些产品不像当今的 Javascript 框架世界那样模块化,而后者又可以或多或少地组合在一起自由地。
I see no reason why a technology, that can serve complex applications over the web, should notbe called a web server, or web application server!
我不明白为什么一个技术,能够满足复杂的应用程序通过网络,应该不会被称为Web服务器或Web应用程序服务器!
If you combine, let's say Nuxtas a frontend, with Feathersas a backend - you'll have a backend serving a REST API and a server-side rendered UI!
如果合并,假设Nuxt作为前端,Feathers作为后端 - 您将拥有一个提供 REST API 的后端和一个服务器端呈现的 UI!
Of course, you could (mis)use that to serve static content - then I'd call it a web server, or you could use it to make and serve a full application - then I'd call it a web application server.
当然,您可以(错误地)使用它来提供静态内容 - 然后我将其称为 Web 服务器,或者您可以使用它来制作和提供完整的应用程序 - 然后我将其称为 Web 应用程序服务器。
It's the combined features or qualities that sum up to serve a purpose - right? - Features like stability, scalability and such are IMHO something that will be added to those technologies, over time. For now, they're pretty new still.
综合起来才能达到某种目的,对吗?- 随着时间的推移,稳定性、可扩展性等功能将被添加到这些技术中。目前,它们还很新。
回答by stuckedoverflow
No it's a runtime environment... so it is not a web server yet it does not need one to run. So probably this is why it could be confusing. It can run standalone without needing any webserver because it is a runtime itself but again it is not a webserver.
不,它是一个运行时环境……所以它不是一个 Web 服务器,但它不需要运行。所以可能这就是它可能令人困惑的原因。它可以独立运行而无需任何网络服务器,因为它本身就是一个运行时,但它又不是网络服务器。

