Node.js入门
Node.js入门
Node.js是什么,这里就不再多说。经过我简单测试,执行相同的任务,Node.js(单进程)比Nginx+php快4倍,当然,这并不表示Node.js的性能就是Nginx+php的4倍,可能不同的任务场景表现各有差异。但这足以让我有兴趣去了解它了。
Node.Js入门[PDF+相关代码]
Node.js入门开发指南中文版
Node.js可以说就是js,作为php程序员,之前接触的js完全是围绕着浏览器工作的,现在改在服务器上工作了,还有一些不适应的地方,如下:
一,自定义模块
module.js
var cfg = {"info":"Require test."};
module.exports = {
print_hello : function() {
return "Hello,World!";
},
print_info : function() {
return cfg.info;
}
};
main.js
var m = require("./module.js");
console.log( m.print_info() );
二,接收参数
1,get.js
var 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.js
var 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/");
更多详情见请继续阅读下一页的精彩内容:
Node.js安装与配置
Ubuntu 编译安装Node.js
Node.js 的详细介绍:请点这里
Node.js 的下载地址:请点这里
|
评论暂时关闭