server.js文件如下 var http = require(“http”); var url=require(“url”);
function start(route,handle) { function onRequest(request, response) { var pathname=url.parse(request.url).pathname;//这里的pathname是访问的url,解析出来 console.log("request for “+pathname+"received.”);
route(handle,pathname);
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
http.createServer(onRequest).listen(8888); console.log(“Server has started.”); }
function start() { console.log(“Request handler ‘start’ was called.”); }
function upload() { console.log(“Request handler ‘upload’ was called.”); }
exports.upload = upload; exports.start = start;