var http =require(“http”);
var server=http.createServer();
function onRequestCallBack(request,response) { console.log(“Request Received.”); response.writeHead(200,{"Content-type": "text/plain"}); response.write(“Hello JasonW”); response.end(); }
server(onRequestCallBack).listen(8888);
console.log(“Server has started.”);
server(onRequestCallBack).listen(8888); 这一行明显不对吧。callback要么在createServer的时候传递,要么用server.on('request’, onRequestCallBack)…
这样吗? 也不对哦!
var http =require(“http”); var server=http.createServer();
function onRequestCallBack(request,response) { console.log(“Request Received.”); response.writeHead(200,{"Content-type": "text/plain"}); response.write(“Hello JasonW”); response.end; };
server.on('request’,onRequestCallBack).listen(8888);
console.log(“Server has started.”);
楼主看的是什么书?监听的也是8888 话说,你是不是想写成这样 function start(route, handle) { function onCreate(request, response) { var postData = ""; var pathname = url.parse(request.url).pathname; console.log(“Request for " + pathname + " received.”);
request.setEncoding("UTF-8");
request.addListener("data", function(postDataChunk) {
postData += postDataChunk;
console.log("Received POST data chunk '"+ postDataChunk + "'.");
});
request.addListener("end", function() {
route(handle, pathname, response, postData);
});
}
http.createServer(onCreate).listen(8888);
console.log("Server has started");
} exports.start = start; 这是写的例题server的一部分