server.js
var http=require('http');
var url=require('url');
function start(route){
function onRequest(request,response){
var pathName=url.parse(request.url).pathname;
console.log("request for"+pathname+"received");
route(pathname);
response.writeHead(200,{"Content-type":"text/plain"});
response.write("hello world");
response.end();
}
http.createServer(onRequest).listen(3000);
console.log("Server has started");
}
exports.start=start;
router.js
function route(pathName){
console.log("About to route a request for"+pathName);
}
exports.route=route;
index.js
var server=require("./server");
var router=require("./router");
server.start(router.route);
网友评论