毕业设计外文文献-Node.js的比较分析(服务器端JavaScript)_第1页
毕业设计外文文献-Node.js的比较分析(服务器端JavaScript)_第2页
毕业设计外文文献-Node.js的比较分析(服务器端JavaScript)_第3页
毕业设计外文文献-Node.js的比较分析(服务器端JavaScript)_第4页
毕业设计外文文献-Node.js的比较分析(服务器端JavaScript)_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、附录A外文翻译一原文局部A Comparative Analysis of Node J s (Server-Side JavaScript) 文章来源: s:/cgi/viewcontent.cgi?referer= s:/ google /& sredir= 1 &article= 1004&context=csit_etdsChapter 1: IntroductionNode.js (Node) 1 is a cross platform runtime environment originally developed in 2009 by Ryan Dahl for developi

2、ng server-side applications. It can be regarded as server-side JavaScript. It was created to address the issues platforms can have with the performance in network communication time dedicating excessive time processing web requests and responses. Node.js is a platform built on Chromes JavaScript run

3、time fbr 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 I/5Node has become popular as it makes creating high perfo

4、rmance, real-time web applications easy. Node allows JavaScript to be used end to end, both on the server and on the client. JavaScript has originally run only in the web browser, but the considerable demand has brought it to the server-side. JavaScript has developed very much and has exceled to dom

5、inate server-side scripting. We need to analyze the security issues in Node applications because of its use with JavaScript, which has security liabilities. Node is event-based rather than thread-based. Node uses an event loop within a single thread instead of multiple threads, and is able to scale

6、to millions of concurrent connections. In Node, a single thread can accomplish a high concurrency.Every I/O operation in Node is carried out in an asynchronous fashion, meaning that the server can continue to process incoming requests while the I/O operation is taking place 2. Because Node is also a

7、synchronous, AJAX (See Chapter 3) could be mistakenly considered equivalent to Node, though they are significantly different.Objectives of our StudyJavaScript was created shortly after the World Wide Web (WWW) came into existence. JavaScript has played an integral role in adding interaction to the u

8、ser interface of web applications and websites until the recent release of HTML5 (Hyper Text Markup Language) and modern JavaScript frameworks. JavaScript is also an integral part of AJAX which was introduced in late 1990s with the advent of Web 2.0 to add real-time like interactivity in the webpage

9、s. Despite all of this progress, JavaScript has been considered as the scripting language for clientside programming (that runs only from the browser). However, this approach has changed with the development of server-side JavaScript (among which Node is considered prominent). Node has not just stre

10、ngthened server-side JavaScript, but also has been competitive with other popular src = u HYPERLINK :/code :/code, jquery. com/jquery-1. 6. 0. js ”。然后,通过全局 jQuery 对象引用 该模块。这个过程污染全局命名空间并可能导致潜在的命名冲突8。Node没有定义一些 全局变量,而是引入了模块化系统(参见第1章)。可以定义自己的模块,也可以使用核心 模块或第三方模块。Node附带了许多核心模块,如 , net和fs。这些模块是用于构建 现代应用程序

11、的基本工具包。节点中的模块化成为可能因为这三个全局变量:require, module 和 exports 8全球对象8浏览器JavaScript中有一个名为window的全局对象。变量可以在 window对象中定义,使其全局可用于应用程序代码的所有局部。Node实现了具有明确别离 的全局变量。在Node中,这两个全局对象用于这个目的:global:与JavaScript中的窗 口对象类似,任何属性都可以附加到全局使变量可以从应用程序代码中的任何位置访问。进程:在Node中有一个为所有相关内容分配的进程对象到全球执行的背景。在 JavaScript中,有一个窗口对象。在Node中,任何时候只有

12、一个进程给定时间。例如, 在JavaScript中,窗口名称是window, name,而在Node中,窗口名称是进程的名称是 process. titleo缓冲JavaScript的另一个缺点是它支持处理二进制数据8。操纵在 JavaScript语言中,二进制数据的支持很少,即使它经常是必需的。Node的Buffer类通 过提供API来轻松操作二进制文件来解决这个缺陷数据14。 Buffer是Node添加到四种原始数据类型(布尔值,字符串,数字和 RegExp)和前端的无所不包的对象(数组和函数也是对象)JavaScript的。它使用极其高 效的数据存储9。Buffer是一个表示固定内存分配

13、的全局对象,其行为类似于数组八位 字节,有效地让二进制数据在JavaScript中表示。大多数Node API都是如此执行数据I / 0获取并将数据导出为缓冲区8。第 3 章:AJAX 与 Node, js节点经常与另一种技术AJAX混淆,但两者都是完全混淆的不同,服务于不同的目的。AJAX 和Node之间唯一的相似之处在于它们都运行在JavaScript上。而Node主要用于服务器 端操作以开发完整的服务器端应用程序,AJAX用于动态的客户端操作更新页面内容而不刷 新它。通过讨论可以更清楚地说明这一点什么是AJAX,为什么使用它,它的局限性以及Node 如何证明优越性实现AJAX的那些限制。

14、AJAXAJAX 18是“异步JavaScript和XML”的缩写,是一组创立高度互动的网站和Web 应用程序的技术18 o AJAX很广泛用于指使用JavaScript从客户端与服务器通信的所有 方法。虽然,AJAX主要用于异步通信,但主要涉及XML数据传输,它可以是同步的,可以 使用其他数据格式,如JS0N 16 o AJAX改变了用户在网络上的互动方式。应用程序不再 需要刷新整个页面以响应每个用户输入。使用AJAX,应用程序可以调用服务器上的特定过 程并仅更新网页的特定局部。之前AJAX,网页上的交互性相当笨拙和昂贵。因为,对于任 何用户交互发生,需要在服务器上生成页面的更新版本,发送回

15、浏览器并呈现。即使所需 的更新是微小的,结果也是如此总是一个全新的页面刷新。这种模式浪费了带宽和资源。AJAX通过在粒度级别修改过程简化了这种方法17 o在AJAX中,JavaScript代码 使用浏览器中内置的特殊对象:XML Request对象用于翻开与服务器的连接并从中下载 数据服务器18。AJAX是用于向其发送数据和从中检索数据的机制服务器与AJAX。制作 AJAX请求和获取的所有步骤回复,列如下16:.使用。创立 XML Request 对象 XML Request ()构造函数。.该对象用于发出 请求。为此,使用。初始化对象open ()方法,它接受三 个参数:Request Ty

16、pe (String: POST, GET 或 HEAD), URL (String)和 Asynchronous (布 尔)。. xml 对象的readyState属性保存响应的当前状态。有五种可能的状态(0- 4): 0表示未初始化,1表示加载,2表示加载,3表示交互,4表示完成。.将响应发送回客户端。FigureClassic 与 AJAX Web 应用程序模型32在图14中,我们说明了 AJAX调用所需的所有步骤。在这个例子中,使用AJAX,客 户端使用文本更新文本中带有城市天气预报的文本从windows onload事件18发起的文 本文件中读取。? PHP/processjson.

17、 php从data, json文件中读取内容并返回AJAX调用的例如AJAX使 应用程序能够更新页面,仅响应页面上的用户操作。它无法解决来自服务器的更新问题。 它没有提供推动的方式从服务器到浏览器的信息17。使用AJAX,客户端总是必须查询服 务器不断获取可用于应用程序的任何新信息或数据。该服务器无法在未事先询问的情况下 将信息推送到客户端。结果是应用程序用户除非从服务器请求数据,否那么不会看到数据。 反过来,数据应用程序获取的内容将过时,即数据不是实时的。这是哪里AJAX似乎不如 Node提供的。虽然,有一些技术使用AJAX如AJAX轮询和AJAX长轮询,使应用程序实时 模拟。这些方法有一些

18、警告。AJAX 投票32在AJAX轮询中,请求以定期的间隔从客户端发送到服务器是时候检查可用的任何 新更新了。如果有任何新的更新可用服务器,他们被送回。这种方法的缺点是仍然存在延 迟和不会复制实时通讯。此外,还会有很多请求和回复,并且从客户端和服务器即使没有 更新。AJAX 投票32AJAX长轮询32,另一种方法是AJAX长轮询,这只是AJAX轮询的一个小变化。与 常规轮询一样,当服务器接收请求时,它会立即返回新数据(如果是)。可用。但是,如果没有要返回的新数据,那么服务器会保持连接翻开,并且一旦可用, 就返回数据。一旦客户端收到数据,客户端立即再次向服务器发送另一个请求。如图16所 /Jn

19、oAJAX长轮询32使用Socket. io进行实时应用程序开发32除了 AJAX轮询和AJAX长轮询之外,还 有更多的技术来建立客户端和服务器之间的实时通信,或者至少像SSE一样(服务器发送 事件)和Web套接字。但没有任何事情可以完成双向工作客户端和服务器之间的通信实时 像Socket, io那样。SSE允许服务器将数据推送到客户端,但客户端无法将数据发送回服 务器。Web套接字允许在客户端和服务器之间双向同时进行双工通信,但它是一个完全新 的协议。Socket, io是一个用于实时Web应用程序的库。它是一个内置Node的模块,它可 以安装在Node应用程序中:npm install s

20、ocket, ioSocket, io是事件驱动的,具有服务器端和客户端组件类似的APR基本上, Socket, io由两局部组成:安装在节点的 服务器上或附加到节点的 服务器的服 务器。允许与服务器交互的客户端库。客户端和服务器局部基本上都做同样的事情:允许 发送(或发布事件并提供定义事件处理程序的方法。为了设置Socket, i。服务器组件,应 遵循以下步骤:创立Socket, io服务器并将其附加到现有 服务器。定义服务器在连接时将 执行的操作。在该连接处理程序中:。定义服务器将处理其他自定义事件的内容。发送消 息。同样,为了在客户端上设置Socket, io,可以遵循以下步骤:引入客户

21、端库。创立套接字对象(连接的接口)。使用该套接字对象:o发送消息。定义在特定事件上触发的回调。要了解Socket, io的实际用法,请考 虑图17中的以下脚本实现了与AJAX相同的天气更新场景。服务器端Node, js脚本如图17 所示。功能很重要语句在评论局部中描述。26, Socket, io服务器端脚本例如在该例如中,用于数据交换的data, json文件显 示为: “city”: Minneapolis”, max_temp: 42, min_temp: 10 27第4章:为什么选择Node, js? Node一直深受开发人员欢迎,其成功吸引了众多高 科技人士采用Node取代现有技术的

22、公司。有许多Node受欢迎的原因以及为什么应该使用 Node进行应用程序开发。高性能Web服务器5随着Web 2.0的出现和不同设备中的 Internet连接:cell手机,平板电脑,台式机和笔记本电脑;适用范围已大大扩大。对齐 需要支持更多用户并提供实时体验。应用已成为主要挑战。安装新硬件时增加了功率。在 应用程序中不断增加对速度和更快连接的需求,但事实并非如此最优的解决方案,因为它 更昂贵。Node试图通过引入来解决这个问题。架构称为Web服务器的事件驱动编程。节 点效率更高。内存比传统服务器,并尽可能保持提供非常快的响应时间,许多并发用户。 这是因为Node在单个线程中运行,并且只要No

23、de必须运行,做一些缓慢的事情,比方等 待确认,它只是继续服务另一个请求。传统方法可以通过多线程来实现这一点,这需要更 多的存储器。同时,传统方法很复杂并且涉及上下文切换。节点是在这方面优选的是,提 供更廉价,可扩展和高性能的应用环境。JavaScript的受欢迎程度19从WWW开展的早期开始,JavaScript 一直存在于浏 览器中。甚至当AJAX出现时,JavaScript是至关重要的。这导致了 JavaScript的普及尽 管有一些批评,但在开发商中间。无论哪种服务器端脚本语言使用过,JavaScript一直是 客户端脚本的选择。熟悉JavaScript和Node加入JavaScrip

24、t,具有在服务器端和许多其 他方面编写代码的功能,功能开发人员采用Nodeo通过利用JavaScript的最正确功能。语 言和培育一个充满活力的社区,Node已成为一个受欢迎的平台和框架,持续采用增长。一种语言多功能19。Node允许在服务器端和客户端运行JavaScript代码。节点 有将JavaScript提升到应用程序开发的新高度。在Node中开发的任何系统将从本地或客 户端平台上的任何地方运行,或从高端节点运行。服务器在别处托管此外,还有数千个免 费的Node模块可供使用。可以使用Node的内置Web服务器在本地开发应用程序。所以, 不像其他人编程语言,需要单独的Web服务器才能托管甚

25、至是托管语言。经过测试,Node 拥有它所需的一切-Web服务器,客户端脚本和服务器端。脚本。简单的开发环境19通常,为新工程建立开发环境对开发人员来说很麻 烦。这需要时间和精力,第一步涉及到。开发环境正确,确保安装所有软件包,必需的 版本,然后将代码放入存储库进行测试。传统的很屡次,环境要求开发人员回顾并检查 是否遗漏了某些内容。节点简化了这一过程,提高了开发人员的工作效率。在Node环境 中,开发人员只需下载Node,从存储库中提取代码,然后从那里开始。节点安装程序适 用于所有主要操作系统:Mac, Linux, Windows和SunOS。来源代码也可以从头开始下载 和构建。所以,设置节

26、点开发环境相对简单得多(见附录)。良好声誉19Node在科技行 业赢得了良好的声誉。技术方面的许多大玩家行业正在使用Node。节点在许多备受瞩目 的技术堆栈中发挥着关键作用依赖其独特优势的公司。Node为Microsoft Azure用户提 供了第一个端到端JavaScript体验,用于开发全新的实时应用程序。Node的I /。事件 模型使eBay免于担忧锁定和并发问题。常见于多线程异步I / 0.在服务器端,整个移动 软件Linkedln的堆栈完全是在Node 30中构建的。PayPal在从现有工程的Java迁移 到Node后,看起来很重要,改进Java。使用Node,重写的应用程序在一半的

27、时间内以 较少的时间交付开发人员,使用较少的代码行,但能够处理两倍的请求,延迟减少三分 之一。因此,他们看到他们的开发和产品性能提高,切换后显着19。第5章:Node, js安全性编程领域对JavaScript的需求激增,其范围已扩大客户端到服务器端。因此, SSJS (服务器端JavaScript)功能几乎可用无处不在,无论是在数据库服务器(如 Mongo DB),文件服务器和Web服务器(如Node)中。JavaScript向SSJS的这一举动带 来了许多好处,但也捆绑了一些安全方面的缺点。客户端脚本注入,已存在很长时间了 被利用来在服务器上执行。服务器端脚本注入同样容易意外地引入服务器端

28、应用程序代 码,因为它们用于客户端代码。相比之下,SSJS注射的效果要严重得多。其中一个漏洞 就是跨站脚本。由于Node基于JavaScript,因此也容易受到跨站点的攻击XSS是一种攻击,允许攻击者在Web应用程序中注入恶意脚本。XSS漏洞是由Web 应用程序中的故障导致的,无法正确验证用户输入。通过颠覆客户端脚本语言,攻击者 可以完全控制受害者。server-side scripting languages with respect to performance and scalability. In this paper, we will describe the advantageou

29、s features of Node. The underlying features of Node: single-threaded, event-driven I/O, and asynchronous programming are discussed with sufficient examples to give better insight into the working architecture of Node that led to Nodes success. In this paper, we also distinguish Node from JavaScript,

30、 which is the backbone on top of which Node has been developed. The same is true of AJAX, which is often time confused with Node. We perform an analysis of Nodes performance with real-time data by implementing two well known applications (Fibonacci number calculation and reading large text file). Fo

31、r further development and enhancement, we also highlight the existing limitations and deficiencies of Node.Simple Server with Node.jsOne of the common uses of Node is to build servers. Node can be used to create different types of servers 7. A simple (Hyper Text Transfer Protocol) web server that re

32、sponds u Hello Node!” to every request it receives can be created with very few lines of code. Type the following code in the text editor, save it as hello_server.js and execute it by typing node hello_server.js from the command prompt. Then, visit this URL: HYPERLINK :/localhost:8000 :/localhost:80

33、00 which should print the Hello Node!” message in the browser.Description of Figure 1 is as follows 6:0. The use strict* string is a directive that enables strict mode, which is a restricted subset of the language that fixes a few important language deficiencies and provides stronger error checking

34、and increased security. For example, strict mode makes it impossible to accidentally create global variables.Imports the module and assign it to the object.Defines the port number from which the server will be accepting connections.Create the web server by calling the factory method from the module

35、and send it a callback function. This anonymous function takes req and res ( request and response) objects as parameters. Every time a client makes a request, this function will get called.Displays to standard output the request information (method, requested resource, and request headers) followed

36、by a new line.Writes the response line and header fields. A status code need to be specified (200, for example, when the request was successful) and an object with all the response headers.Writes the response body before the end method closes the connection.Tells the web server to start accepting co

37、nnections on the specified port.Call the console.log method to print the information to standard output.Node.js ModulesModules are plugins, add-ons, and extensions for Node to help with the development process. The Node module exposes a public API (Application Programming Interface) that one can use

38、 after the module is imported into the current script. Node modules can be categorized as core modules, third party modules, and local modules. Core modules are modules that come with Nodes installation and are preloaded when a Node process starts. Core modules are referenced simply by name while lo

39、cal modules and third party modules maps into a file path. Third party modules are modules registered in NPM and installed using npm command. NPM by default dumps modules installed from NPM repository into node_modules local directory. And local modules are self-created modules 9.Sharing objects amo

40、ng files in a Node application is possible only by using the CommonJS module system. For a module to expose an API, module and module.exports are used, module is a variable representing the module currently in consideration and module.exports is the object that the module will export to other script

41、 that requires this module. For instance, a module can be created that exports a set of functions as shown in Figure 2 9.NPM: Node Package ManagerBesides writing local modules oneself, and using default modules provided by Node, modules written by other people in the Node community can be used. Also

42、, self-created local modules can be published for others. NPM which stands for Node Package Manager is the most common way to do so 10.NPM is a built-in tool that is included by default with every installation of Node. NPM helps in easily managing modules in Node projects by downloading packages, re

43、solving dependencies, running tests, and installing command line utilities 8. The main purpose of the NPM modular system is to ease the availability and installation of bunch of publicly available, reusable components via an online repository, with version and dependency management. Modules are plug

44、ins, add-ons, and extensions for Node to help with the development process. A full list of packaged modules can be found on the NPM website HYPERLINK s:/ s:/, or accessed using the NPM CLI (Command Line Interpreter) tool that automatically gets installed with Node. The Nodes module ecosystem is open

45、 to all, and anyone can publish their own module to be listed in the NPM repository 11.To ensure the successful installation of NPM, issue the following command which should display the NPM version 8: npm -version 7 To install modules via npm, npm install command should be used which requires the na

46、me of the module package to be installed and its version. For instance, mysql module package can be installed by issuing this command 10: npm install mysql2.0.0.NPM installs module packages to the node_modules subdirectory of the project. Thousands of modules in the registry can be explored using th

47、e search and view commands. The search command is useful when the name of the package to be installed is not known so it prints the name and description of all matching published modules 8, 10.package.json is a JSON (JavaScript Object Notation) file that allows to locally manage installed npm packag

48、es. It serves as documentation for what packages the project depends on, allowing to specify the version of a package that the project can use 31.How Node.js Works?The main distinctive features of the Node architecture are the usage of non-blocking, event driven, asynchronous I/O calls that operate

49、in a single thread. Conventional web servers handle concurrency by spawning new threads for each new request, which can max out the available memory. Node is lightweight, efficient, and different. It is able to support tens of thousands of concurrent connections because of its unique features. Even

50、with limited memory and a single thread, Node can achieve high concurrency rate without having to perform context switching between threads 12.The Node architecture and its working mechanism can be better clarified by understanding its underlying features and comparing it with previous approaches.No

51、n-Blocking Event LoopNode is non-blocking in the sense that it is able to service multiple requests, and it doesnt waste clock cycles in I/O tasks as is the case in the conventional blocking model. The conventional blocking model tends to block subsequent requests sent to a server when it is perform

52、ing I/O operations such as reading content from a database. In order to be non-blocking, Node uses an event loop, a software pattern that facilitates non-blocking I/O combined with event-driven I/O, a scheme where a registered event callback function is invoked when some action happens in the progra

53、m 3.Consider this blocking PHP (Hypertext Pre-processor) code and non-blocking Node.js code in Figure 3 and Figure 4 respectively 8.In the first example, the PHP sleep() function blocks the thread of execution. While the program is sleeping, it does not perform any tasks but waits for the time speci

54、fied. The execution is thus blocked as long as it is specified. And no other instructions are executed until the specified time elapses, indicating its synchronous. Node on the other hand, leverages the event loop. So, even the use of blocking, setTimeout() is non-blocking in the latter case. It reg

55、isters an event for the future and lets the program continue to run, therefore being asynchronous.Single-Threaded ModelNode is a process that runs in an event loop making use of a single thread to service any requests. Whereas other web servers like Apache spawn a new thread per request, which start

56、s with a fresh state every time 8. Node is powerful considering the way it permits non-blocking I/O to occur in a single thread which makes the overhead of Node very small, because no new threads are created. When a Node application needs to perform operations, it sends an asynchronous task to the e

57、vent loop, registers a callback function, and then continues to handle other operations. The event loop keeps track of the asynchronous operation, executes the given callback and when it completes, returns its result to the application. Node is able to handle a large number of operations (even with

58、a single thread) by managing the thread pool and optimizing the task execution, such as client connections or computations 13.Consider the following getLanguages() function in Figure 5. This function gets executed every time the user makes a request to the getLanguages() function and returns a colle

59、ction of languages in HTML form.附录B外文翻译一译文局部Node.js的比拟分析(服务器端JavaScript)文章来源: s:/cgi/viewcontent.cgi?referer= s:/ google /& sredir= 1 &article= 1004&context=csit_etds第1章:简介Node.js (Node) 1是一个跨平台运行时环境,最初由Ryan Dahl于2009年开发, 用于开发服务器端应用程序。它可以被视为服务器端JavaScript。它的创立是为了解决 平台可能遇到的问题,网络通信时间的性能使得处理Web请求和响应的时间

60、过长。“Node.js是一个基于Chrome JavaScript运行时的平台,可轻松构建快速,可扩展的网 络应用程序。Node.js使用事件驱动的非阻塞I/O模型,使其轻量级和高效,非常适 合跨分布式设备运行的数据密集型实时应用程序1。Node已经变得流行,因为它可以轻松创立高性能,实时的Web应用程序。Node 允许在服务器和客户端上端到端地使用JavaScripto JavaScript最初只在Web浏览器中 运行,但是相当大的需求已经将它带到了服务器端。JavaScript已经开展得非常多,并 且已经超越了服务器端脚本。我们需要分析Node应用程序中的安全问题,因为它与 JavaScr

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论