If you just want to get the file size, it is better to use HTTP HEAD , which returns only response headers from a server without a body.
You can make a HEAD request in Node.js as follows:
var http = require("http"),
requestOpts = {
host: "www.google.com",
port: 80,
path: "/images/srpr/logo4w.png",
method: "HEAD"
};
var request = http.request(requestOpts, function (response) {
console.log("Response headers:", response.headers);
console.log("File size:", response.headers["content-length"]);
});
request.on("error", function (err) {
console.log(err);
});
request.end();
EDIT:
, , : " Node.js?". , response.destroy():
var request = http.get("http://www.google.com/images/srpr/logo4w.png", function (response) {
console.log("Response headers:", response.headers);
response.destroy();
response.on("data", function (chunk) {
console.log("received data chunk:", chunk);
});
});
, destroy() , . , , HTTP HEAD.