这是一个普通的节点练习,即使使用可Realable.Once(" end"),每个请求两次启动(" end")回调。这是THA代码:
require("http").createServer(function (req, res) {
var readable = require("fs").createReadStream("./image.jpg",{highWaterMark:1024*1024});
readable.on("data", function (data) {
res.write(data);
})
readable.on("end", function () {
res.end()
console.log("Ended");
})
}).listen(9000, function () {
console.log("Listening.... on 9000");
});
每当您请求一页为主目录的第一页时,都会发送2个请求"/",而另一个请求" favicon.ico",以便为什么该功能在为了解决for req.URL的IF条件并对其进行分配您想要的目录并将起作用的条件。