Node.js、PHP、Javascript 混淆

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16384339/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 04:26:17  来源:igfitidea点击:

Node.js, PHP, Javascript Confusion

phpjavascriptnode.js

提问by Orvyl

I am totally lost of what Node.js is all about so here's my question:

我完全失去了 Node.js 的全部内容,所以这是我的问题:

Is node.js a new language which can replace PHP or it is a language which can/only compliment/supplement PHP and other web languages to perform complex task?

node.js 是一种可以替代 PHP 的新语言,还是一种可以/只能补充/补充 PHP 和其他 Web 语言来执行复杂任务的语言?

采纳答案by slobodan.blazeski

Node.js is server side Javascript environment based on chrome V8 javascript engine. It enables you to write your server code in javascript, instead of choosing one of the "traditional" web languages such as PHP, c#, python, ruby, perl etc. Using node.js and database such as mongodb you could write your web application completely in javascript.

Node.js 是基于 chrome V8 javascript 引擎的服务器端 Javascript 环境。它使您能够用 javascript 编写服务器代码,而不是选择一种“传统”网络语言,例如 PHP、c#、python、ruby、perl 等。使用 node.js 和数据库(例如 mongodb)您可以编写您的网络应用程序完全在javascript中。

Here's example of the full stack for web development:

以下是用于 Web 开发的完整堆栈示例:

  • Backbonefor client side, code that runs in the browser (chrome,firefox)
  • Expressserver side framework running on Node.js
  • Mongodbdatabase for storing documents
  • 客户端的主干,在浏览器中运行的代码(chrome、firefox)
  • 在 Node.js 上运行的Express服务器端框架
  • 用于存储文档的Mongodb数据库

Above mentioned technologies will enable you create your application writing only javascript code, from browser to server and finally to database, sort of one language to rule them :), no need for PHP unless you have legacy codebase .

上面提到的技术将使您能够创建您的应用程序,只需编写 javascript 代码,从浏览器到服务器,最后到数据库,一种语言来统治它们:),除非您有遗留代码库,否则不需要 PHP。

回答by Dirk

First you have to understand the difference between server-side and client-side code.

首先,您必须了解服务器端和客户端代码之间的区别。

Server-side code runs on the server, and it can do stuff like reading a database, getting file contents from the server, send mails etc. Examples of server-side code are PHP, Node.js, ASP.

服务器端代码在服务器上运行,它可以执行诸如读取数据库、从服务器获取文件内容、发送邮件等操作。服务器端代码的示例有 PHP、Node.js、ASP。

Client-side code runs in the users webbrowser. It is used to make webpages interactive. This is mainly written in JavaScript.

客户端代码在用户浏览器中运行。它用于使网页具有交互性。这主要是用 JavaScript 编写的。

PHP and Node.js are both server-side programming languages (altough node is a framework, but lets not make this any more complicated). They can both do things like database processing, reading files. As far as I know, you can't use both PHP and Node.js at the same time, so they can't even work together (there is probably some way to achieve this)

PHP 和 Node.js 都是服务器端编程语言(虽然 node 是一个框架,但不要让它变得更复杂)。它们都可以做诸如数据库处理、读取文件之类的事情。据我所知,你不能同时使用 PHP 和 Node.js,所以它们甚至不能一起工作(可能有某种方法可以实现这一点)

So to wrap it up: Node.js and PHP are both server-side and they can do the same thing. Node.js can replace PHP and vice versa

所以总结一下:Node.js 和 PHP 都是服务器端,它们可以做同样的事情。Node.js 可以替代 PHP,反之亦然