什么是像 NodeJS 这样的服务器端 javascript 中的“服务器”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34511505/
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
What is "server" in server-side javascript like NodeJS?
提问by Divs
Is it not a Javascript engine hosted by the browser on the client machine itself?
它不是由客户端机器上的浏览器托管的Javascript引擎吗?
采纳答案by Quentin
No, it isn't.
不,不是。
Server generally has two meanings:
服务器一般有两个意思:
- A piece of software that listens for network requests and then responds to them
- A computer running such a piece of software
- 一种侦听网络请求然后响应它们的软件
- 一台运行这种软件的电脑
A Node.JS server can be either of those.
Node.JS 服务器可以是其中之一。
In web programming, a Node.JS server takes the place of Perl, Python, Ruby, PHP, Scala, etc. (And like those other languages, Node.JS lets you use JavaScript for non-server and non-web purposes).
在 Web 编程中,Node.JS 服务器取代了 Perl、Python、Ruby、PHP、Scala 等(与其他语言一样,Node.JS 允许您将 JavaScript 用于非服务器和非 Web 目的)。
Generally the server itself is run directly from Node (e.g. with this library) rather than being embedded in another server like Apache (as is most common for PHP).
通常,服务器本身直接从 Node 运行(例如使用这个库),而不是嵌入在另一个服务器中,比如 Apache(这对于 PHP 来说是最常见的)。
A browser doesn't need to be involved at all. If one is, then it will probably be one acting as a client and making a request to the server. That said, tools like PhantomJS can allow a browser to be driven from Node (and other programming languages).
浏览器根本不需要参与。如果是,那么它可能会充当客户端并向服务器发出请求。也就是说,像 PhantomJS 这样的工具可以允许浏览器由 Node(和其他编程语言)驱动。
回答by Rahul Tripathi
From here:
从这里:
Server-side JavaScript (SSJS) refers to JavaScript that runs on server-side and is therefore not downloaded to the browser. This term is used to differentiate it from regular JavaScript, which is predominantly used on the client-side (also referred to as client-side JavaScript or CSJS for short).
服务器端 JavaScript (SSJS) 是指在服务器端运行的 JavaScript,因此不会下载到浏览器。该术语用于区别于常规 JavaScript,后者主要用于客户端(也称为客户端 JavaScript 或简称 CSJS)。
回答by Igor Skoric
NodeJS runs on the V8 JavaScript Enginewhich does not have to be in a browser. It just executes JS. It does not depend on what you do with it. In the case of a NodeJS server, it listens to HTTP requests and is therefore a server.
NodeJS 在V8 JavaScript 引擎上运行,而不必在浏览器中。它只是执行JS。这不取决于你用它做什么。在 NodeJS 服务器的情况下,它侦听 HTTP 请求,因此是一个服务器。
回答by Ashutosh Singh
Node.js is a framework/program that is installed on a machine and contains code written in javascript and process those codes requested by a client like a browser, Yes each browser contains its own engine that process the javascript.
Node.js 是一个安装在机器上的框架/程序,它包含用 javascript 编写的代码并处理客户端请求的那些代码,如浏览器,是的,每个浏览器都包含自己的处理 javascript 的引擎。