node.js learning example 1 (阻塞)
来源:互联网 发布:如何在淘宝上 编辑:程序博客网 时间:2024/05/01 22:00
1.index.js
var server = require("./server");var router = require("./router");var requestHandlers = require("./requestHandlers");var handle = {}handle["/"] = requestHandlers.begin;handle["/begin"] = requestHandlers.begin;handle["/end"] = requestHandlers.end;server.start(router.route, handle);
var http = require("http");var url = require("url");function start(route,handle){function onRequest(request,response){console.log("-----------begin-------------");var pathname = url.parse(request.url).pathname;console.log("pathname-----------"+pathname);var content = route(handle, pathname);response.writeHead(200,{"content-type":"text/plain"});console.log(content);response.write(content);response.end();console.log("-----------end-------------");}http.createServer(onRequest).listen(8889);console.log("Server is starting...");}exports.start = start;
function route(handle, pathname){console.log("Route the request---------"+pathname);if(typeof handle[pathname] === 'function'){return handle[pathname]();}else{console.log("no request handler found for" + pathname);return "404 Not Found!";}}exports.route = route;
function begin(){console.log("handle the 'begin' call!");return "begin!";}function end(){console.log("handle the 'end' call!");return "end!";}exports.begin = begin;exports.end = end;
5. run -- node index.js
- node.js learning example 1 (阻塞)
- node.js learning example 2 (非阻塞)
- Node.js learning resource
- Learning Node.js
- node.js 理解阻塞与非阻塞
- Node.JS阻塞与非阻塞
- Learning Node.js - 知识收集
- learning the node.js together
- Learning Server-Side JavaScript with Node.js
- Simple example - Node.js, Restify, MongoDb and Mongoose
- Node.js学习笔记【1】入门(服务器JS、函数式编程、阻塞与非阻塞、回调、事件、内部和外部模块)
- 理解Node.js的异步非阻塞I/O模型
- Node.js使用exec模拟耗时操作测试非阻塞
- Node.js 异步非阻塞的回调函数
- 浅解Node.js的异步非阻塞I/O模型
- Learning Processing.js - 1
- node.js随笔1-初识node.js
- Node.js 回调函数(阻塞/非阻塞)学习笔记
- 双击C/C++的debug下*.exe一闪而过的解决方案(初学者适用版)
- Outlook Express邮箱设置方法
- socket编程心得
- apache高级配置
- 2013.01.10 SQL测试脚本
- node.js learning example 1 (阻塞)
- imagecreatetruecolor()和imagecreate()的区别
- Body碰撞接触点监听
- 深入剖析printf函数(上):如何不借助第三方库在屏幕上输出"Hello World"?
- Ajax的通信方式
- 词典文件
- 深入浅出K-Means算法
- 堆排序
- UNITY NGUI Sprite分类