百度百科上:
Node.js是一套用来编写高性能网络服务器的JavaScript工具包,一系列的变化由此开始,在Node中,Http是首要的。Node为创建http服务器作了优化,所以在网上看到的大部分示例和库都是集中在web上(http框架、模板库等)。
Node.js的优点
下面我愉前人写的一个资料,让大家更清楚的了解NodeJS,前人的文章
Node 旨在解决什么问题?
Node 公开宣称的目标是 “旨在提供一种简单的构建可伸缩网络程序的方法”。当前的服务器程序有什么问题?我们来做个数学题。在 Java™ 和 PHP 这类语言中,每个连接都会生成一个新线程,每个新线程可能需要 2 MB 的配套内存。在一个拥有 8 GB RAM 的系统上,理论上最大的并发连接数量是 4,000 个用户。随着您的客户群的增长,如果希望您的 Web 应用程序支持更多用户,那么,您必须添加更多服务器。当然,这会增加服务器成本、流量成本和人工成本等成本。除这些成本上升外,还有一个潜在技术问题,即 用户可能针对每个请求使用不同的服务器,因此,任何共享资源都必须在所有服务器之间共享。鉴于上述所有原因,整个 Web 应用程序架构(包括流量、处理器速度和内存速度)中的瓶颈是:服务器能够处理的并发连接的最大数量。
Node 解决这个问题的方法是:更改连接到服务器的方式。每个连接发射一个在 Node 引擎的进程中运行的事件,而不是为每个连接生成一个新的 OS 线程(并为其分配一些配套内存)。Node 声称它绝不会死锁,因为它根本不允许使用锁,它不会直接阻塞 I/O 调用。Node 还宣称,运行它的服务器能支持数万个并发连接。
现在您有了一个能处理数万个并发连接的程序,那么您能通过 Node 实际构建什么呢?如果您有一个 Web 应用程序需要处理这么多连接,那将是一件很 “恐怖” 的事!那是一种 “如果您有这个问题,那么它根本不是问题” 的问题。在回答上面的问题之前,我们先看看 Node 的工作原理以及它的设计运行方式。
Node 肯定不是什么?
没错,Node 是一个服务器程序。但是,基础 Node 产品肯定不 像 Apache 或 Tomcat。本质上,那些服务器 “安装就绪型” 服 务器产品,支持立即部署应用程序。通过这些产品,您可以在一分钟内启动并运行一个服务器。Node 肯定不是这种产品。Apache 能通过添加一个 PHP 模块来允许开发人员创建动态 Web 页,添加一个 SSL 模块来实现安全连接,与此类似,Node 也有模块概念,允许向 Node 内核添加模块。实际上,可供选择的用于 Node 的模块有数百个之多,社区在创建、发布和更新模块方面非常活跃,一天甚至可以处理数十个模块。本文后面将讨论 Node 的整个模块部分。
Node 如何工作?
Node 本身运行 V8 JavaScript。等等,服务器上的 JavaScript?没错,您没有看错。对于只在客户机上使用 JavaScript 的程序员而言,服务器端 JavaScript 可能是一个新概念,但这个概念本身并非遥不可及,因此为何不能在服务器上使用客户机上使用的编程语言?
什么是 V8?V8 JavaScript 引擎是 Google 用于其 Chrome 浏览器的底层 JavaScript 引擎。很少有人考虑 JavaScript 在客户机上实际做了些什么?实际上,JavaScript 引擎负责解释并执行代码。Google 使用 V8 创建了一个用 C++ 编写的超快解释器,该解释器拥有另一个独特特征;您可以下载该引擎并将其嵌入任何 应用程序。V8 JavaScript 引擎并不仅限于在一个浏览器中运行。因此,Node 实际上会使用 Google 编写的 V8 JavaScript 引擎,并将其重建为可在服务器上使用。太完美了!既然已经有一个不错的解决方案可用,为何还要创建一种新语言呢?
事件驱动编程
许多程序员接受的教育使他们认为,面向对象编程是完美的编程设计,这使得他们对其他编程方法不屑一顾。Node 使用了一个所谓的事件驱动编程模型。
清单 1. 客户端上使用 jQuery 的事件驱动编程
// jQuery code on the client-side showing how Event-Driven programming works // When a button is pressed, an Event occurs - deal with it
// directly right here in an anonymous function, where all the
// necessary variables are present and can be referenced directly
$("#myButton").click(function(){
if ($("#myTextField").val() != $(this).val())
alert("Field must match button text");
});
实际上,服务器端和客户端没有任何区别。没错,这没有按钮点击操作,也没有向文本字段键入的操作,但在一个更高的层面上,事件正在 发生。一个连接被建立,这是一个事件!数据通过连接进行接收,这也是一个事件!数据通过连接停止,这还是一个事件!
为 什么这种设置类型对 Node 很理想?JavaScript 是一种很棒的事件驱动编程语言,因为它允许使用匿名函数和闭包,更重要的是,任何写过代码的人都熟悉它的语法。事件发生时调用的回调函数可以在捕获事件处 进行编写。这样可以使代码容易编写和维护,没有复杂的面向对象框架,没有接口,没有过度设计的可能性。只需监听事件,编写一个回调函数,其他事情都可以交 给系统处理!
扩展的模块
模块中包含了很多功能代码片断,在模块中的代码大部分都是私有的,意思是在模块中定义的函数方法和变量,都只能在同一个模块中被调用。当然,可以将某些方法和变量暴露到模块外,这个时候可以使用export对象去实现
首先需要安装nodejs环境,相关文件下载
下载之后,安装之后,在C盘就会出现nodejs的相关目录
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXAAAAGZCAIAAAAfMP0iAAAgAElEQVR4nO2d/XMc1Znv9Y9sXQO7XCdbvluXunVvUrsVcjfZrd1U2K1UirtsBDHGdgjESUyWgNklXC9exEswSHATCoxiG2yHsBJYkQWTsYRlsHmRDTFGwga/27Lxi8Canpmefps+94eRRz19Xvp092nNmZnvp55Ktc+cc/rpnnM+fSTUJ12TB97tYjF54N1QhApl6sQN+hShZOrHggP6nzJ1EAhE+uiaZM2rpgiFVgAzsZBlIBQEQp9grk7Y65RMhSKZBlYoCITOEW9GBWdmpHFip8JSAPNY7Bpm5WDaSrJFIBB0xPiRR/xR+vnJW1MILCYWSqbZIhAIOsKrjOAHzU1Lvg69VkIgEE0JzEMEAqEsIBQEAqEsIBQEAqEsIBQEAqEsIBQEAqEsIBQEAqEsIBQEAqEsIBQEAqEsIBQEAqEsIBQEAqEsIBQEAqEsIBQEAqEstBCKwheFY32apisEAkEHY1uTJpw+sC9BaI8C5kfM3ViCfQpON9n4mrI4t6Z/PQhEa4V2cyZytULrgBYN0zuCg2Dn4k4QCIQgmjxVaFMwJ/kkf6ozu2KWiAUkzg2BQMiElFAyfWJ3UT+GBE8h0ATPF8wSZodijwgWMggEghmyasjCJkxJ8fzCqx/qkHksXxIs5xkNgUDwIsZsUb42CfYcOhasPgQJqBKKzKcIBIKOhLveKzt91AoleN7IFQqvubgTwQoo8nQIBCIYWkwSwQqFFkTkxBb/ICNTk3leBAIRGU1+9tKrEp5BJFcNkSsUcQldDqcgEPKhxX8zFhxMBv4DDf1RqDdBK2bDlN5BIBChaP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hMP+GrTx9xDTN8vSRBRNKZM/yOcRqDkCNZKsMZkkCodB1WlYoq5bQQiluWF0+uLu4YXVh1RLx71DEPweGaobuEf3P+q0U/DBFn058IgBk6GokVEhXE5fwOo9bJ3IwN0wcyUsVkFIotm2XD+5mOqWwfFFh1ZLywd22bafPMzvgDqAVMgMyo0HbfKEQQmzbFvwORVubYCUCQAgthAIAaA8gFACAMiAUAIAyIBQAgDIgFACAMiAUAIAyIBQAgDI0Egp2vQeg1dFFKNj1HoA2QBehYNd7ANoAXYSCXe8BaAP0Ewp2vQdAHQv8omDLCCV9ntmB9wOBKiQ3EGDuPMDsTdxPZB3JN2DnN1sQ15MBQgFACfRmJcztS5h+EQtFsA2KoI548xTm2SEUAHRBfkrHXaHICIUulBQKaacVSleAUGHoOHQQKoxsJU5AnA8AsYgUgYxQmKuYSJuEZoGgJjthQSVJmi4UXol4iShzICkF+fsOQCQyEokrFPl+guUtKZSUu94TiTUC717HbSVIQJAPAPIIVhCxhCLTj2CUtrZQ0ux6XydSH3RhXOVHnjpZcwBqJFtlMEsSCIWu07JCSbrrPRH+DqV+U5hLBmaJuJV4fSjIBwAZuhoJFdLVxCW8zuPWiRzMDRNH8lIFYNd7uANohcyAzGjQNl8oBLveA9AuaCEUAEB7AKEAAJQBoQAAlAGhAACUAaEAAJQBoQAAlAGhAACUoZFQsOs9AK2OLkLBrvcAtAG6CAW73gPQBugiFOx6D0AboJ9QsOs9AOpI9q5Z4jfUWkYo6fNMBt79AwuJ5AYC9D9l9uiQ2cQjVBh3Q4N2EMoCOxiAjKA3K2FuXyLY1kRgEKaVxEKRzKehLeOyYgKhAKAE+QnMXSBI79sm6KejhcJbEDIXaSHHRzolsh8AskAwpenjekkCfaRXTIj/D8SVe3WEzxWcAAAAAElFTkSuQmCC" alt="" />
OK,我们来看一下如何实现request.querystring功能的,即get请求的功能,相关代码如下:
var qs = require('querystring');
var http = require('http');
var formidable = require('formidable');
var exec = require('child_process').exec;
var fs = require('fs');
var filename = ''; var url = require("url"); function start(response, request) {
var getQuery = url.parse(request.url).query;
var getData = qs.parse(getQuery); //getData数据
console.log(getData["zzl"]);
}
别外一种比较标准的写法重到querystring字符串,写法如下:
var http = require("http");
var url = require("url");
var params = url.parse(request.url, true).query;
console.log(params.zzl);
感觉第二种写法更清晰
测试:
http://127.0.0.1:8888?zzl=1234
对于nodejs的console控制台的结果就为:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAARMAAABeCAIAAACPemfpAAAGPklEQVR4nO2bQXLjOgxEdbQcLUfjMssscpW/zl9MTYoRAbDRhDSS3G8xJdMg2ADZtiN7tv86vj4/vr+/vz4/vj4/3t/f397eNiGEiZwjBIOcIwSDnCMEg5wjBAPinNbBrdIGiuSfxKh/V4I3crViCUlgfG2lVa3jioWmTJ3TJ0KSegHZPFcj1u9VtF5peaMOcg6R+YRsRJIa5+yymA+JM3R352zwgS5xTm2vDm1+YfJ/dUgOcY65xhgwHfy57jN4tjSduZuSzdMGoh5Z+qc6vVZM6xrzxMFEflB/Nn5Ue47OQEaQZGXd1tqSc6a6cWWbf/qRay+PJ6kPNtV6FSHJg3GirpI89LpE/DbsxTk6YyX16x7knFj0GLZrNFGJmacfN+eO8Ug5Y3Bc3ShypwfRkO0Jfm3qiUu4oM6pmOJ1y//O8XR7keZ4tkI6z8+/083AKw3GpwuBq2T7A/YQl0TUe7RORHzluiv31tpfEOlgr6fq22+4PL2qQNtU5/TZxZ3zEmbzrKyLx8cjR+s02QVXrnvC9zntN95TwawgLZ6nnxI0dFpCXJ0pCZE6rdesyKslyL8BraPzm1KP0xnQBkA9yLqtze4QIBLPJKhcFKI+z7mXc7blN0ABoj5PuJ1zhLgEco4QDHKOEAxyjhAMco4QDOA3oRe/x3J9hQfxsoX/4J3PqnEX/Nc3F9+hfyival0uz3rh9+2bdz6rriPknIusS+dZFHDBvuGv/fdwjldeH9CPgMpSeQK8eDN/MB7nD5Kv1JXNM04p1x8k2azDXVWvmXxalJd/cTwC/ztnVDxeb05z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