通常のノードでは、on( "end")コールバックはreadable.once( "end")を使用してもリクエストごとに2回発生します。関数はで、二回発射し、なぜそのようにあなたがメインディレクトリのページ1を要求するたびに送信される2つの要求がありますNode.js on( 'end')ストリームのリスナーは2回発生します
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つのリクエストが処理されていることを意味します。 – robertklep
NOpe、これは単なるリクエストです。 –
'.once()'を使用して2回トリガする場合、唯一の合理的な説明は、2つのリクエストが処理されていることです。リクエストハンドラに 'console.log(req.url)'を追加してみてください。 – robertklep