Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / Node.js入门

Node.js是什么,这里就不再多说。经过我简单测试,执行相同的任务,Node.js(单进程)比Nginx+php快4倍,当然,这并不表示Node.js的性能就是Nginx+php的4倍,可能不同的任务场景表现各有差异。但这足以让我有兴趣去了解它了。相关阅读:Node.Js入门[PDF+相关代码]  http://www.linuxidc.com/Linux/2013-06/85462.htmNode.js入门开发指南中文版 http://www.linuxidc.com/Linux/2012-11/73363.htmNode.js可以说就是js,作为php程序员,之前接触的js完全是围绕着浏览器工作的,现在改在服务器上工作了,还有一些不适应的地方,如下:一,自定义模块module.jsvar cfg = {"info":"Require test."};
module.exports = {
 print_hello : function() {
  return "Hello,World!";
 },
 print_info : function() {
  return cfg.info;
 }
};main.jsvar m = require("./module.js");
console.log( m.print_info() );二,接收参数1,get.jsvar http = require("http");
var url  = require("url");
http.createServer(function(request,response) {
 var $get = url.parse(request.url,true).query;
 response.writeHead(200,{"Content-Type":"text/plain"});
 response.end($get["data"]);
}).listen(1337,"192.168.9.10");
console.log(""Server running at http://192.168.9.10:1337/");2,post.jsvar http = require("http");
var querystring = require("querystring");http.createServer(function (request, response) {
        var post_data = "";
        request.addListener("data", function(post_chunk) {
                post_data += post_chunk;
        });        request.addListener("end", function() {
                post_data = querystring.parse(post_data);
                response.writeHead(200, {"Content-Type":"text/plain"});
                response.end(post_data.username);
        });
}).listen(1337, "192.168.9.10");
console.log(""Server running at http://192.168.9.10:1337/");更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2013-11/92635p2.htmNode.js安装与配置 http://www.linuxidc.com/Linux/2013-05/84836.htmUbuntu 编译安装Node.js  http://www.linuxidc.com/Linux/2013-10/91321.htm Node.js 的详细介绍:请点这里
Node.js 的下载地址:请点这里