我是新来的服务器端JavaScript所以Node.js。好了,在这里我想一些很简单的事情,如node.js简单的Web服务器请求生命周期
var http = require("http");
http.createServer(function(request, response) {
console.log("node server");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(2424);
正如我看到的结果是,每当我发出请求到服务器console.log("node server");
执行两次。为什么会发生,节点(或http.createServer
)如何提供请求?
那么,记录请求。如果你从浏览器调用你的服务器,很可能其中之一是favicon。 –
@dystroy两个时间if(request.path!='/ favicon')为真 – Riki
记录请求,不要做这样的测试! –