node.js在Web开发上下文中适合什么位置? [英] where does node.js fit within the web development context?

查看:122
本文介绍了node.js在Web开发上下文中适合什么位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道node.js据说是 V8 Javascript引擎上托管的事件驱动的I/O" 服务器端javascript.我访问了node.js网站,然后阅读了Wikipedia条目,但无法完全了解在哪里使用它以及它如何有用. 事件驱动的I-O"? "V8 Javascript引擎"?不过,在某些情况下,我看到使用服务器端" JavaScript有点矫kill过正.例如,我在node.js的维基百科条目:

I know that node.js is said to be "event-driven I/O" server-side javascript hosted on V8 Javascript engine. I visited the node.js website, and then read the wikipedia entry, but cant quite get the whole idea of where to use it and how it will be useful. "Event-driven I-O"? "V8 Javascript engine"? In some context though, I see that using "server-side" javascript as a little overkill..I take for instance this piece of code in the wikipedia entry of node.js:

var http = require('http');

http.createServer(function (request, response) {
    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.end('Hello World\n');
}).listen(8000);

console.log('Server running at http://127.0.0.1:8000/');

我一直在思考,运行专门提供在应用程序的前端部分执行的javascript文件的服务器真的有一个重要的目的吗?

I have been thinking, is there really a significant purpose in running a server that particularly serves javascript files that are executed in the front-end part of the application?

我还在github上创建了node.js存储库,以了解有关其工作原理的更多信息,结果发现其某些模块是用C ++编写的.那么,那毕竟不是JavaScript吗?

I also forked the node.js repo in github to learn more about how it works, and it turns out that some of its modules are written in C++. So it is not a javascript after all then?

有人可以给我一个清晰的解释吗?很抱歉,如果问题不清楚或有什么问题,我只是一个初学者.将不胜感激任何输入/建议.谢谢

Can somebody give me a clear explanation about all this? Sorry if the question is not clear or something, I am just a beginner. Will appreciate any input/suggestions. thanks

推荐答案

简单来说,node.js服务器是 replacement ,例如Apache Web服务器-但它的编写很大程度上在运行在服务器上(由V8引擎执行)而不是在客户端上运行的JavaScript中.可以使用包装在JavaScript接口中的本机代码"模块(例如用C ++编写)进行扩展,以添加功能,但是AFAIK大多数node.js模块都是纯JavaScript.

The node.js server is, in simple terms, a replacement for something like the Apache web server - but it is largely written in JavaScript which runs on the server (executed by the V8 engine) rather than on the client side. It can be extended with 'native code' modules (written in e.g. C++) wrapped in a JavaScript interface to add functionality, but AFAIK most node.js modules are pure JavaScript.

事件驱动的I/O"只是一个术语,描述了您在JavaScript中惯用的常规异步回调机制.在node.js中,您提供了各种事情的回调,并且在相关事件发生时调用了函数.

"Event driven I/O" is just a term that describes the normal asynchronous callback mechanisms you're used to in JavaScript. In node.js you supply callbacks for all sorts of things, and your function is called when the relevant event occurs.

根据要添加的模块数量,node.js服务器相对于Apache之类的服务器来说相对较轻,并且在某些方面要简单得多.

Depending on how many modules you add, a node.js server is relatively lightweight compared to something like Apache, and in some ways a lot simpler.

我看到的node.js的两个主要优点是:

The two main advantages to node.js I see are:

  1. 它允许您用相同的语言编写Web应用程序的服务器端和客户端部分.在某些情况下,您可以在两侧使用相同的代码.
  2. 它使所有知道JavaScript的所有Web开发人员都可以访问服务器端编码,而不必学习更常见的服务器端语言,例如PHP或Java.

这是我刚遇到的一篇文章,该文章也可能会引起一些启发:什么是Node.js?

Here's an article I just came across that might also shed some light: What is Node.js?

这篇关于node.js在Web开发上下文中适合什么位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆