I am creating an application in node.js that loads multiple pages, parses the contents.
Since node.js sends chunks, I can parse chunks. If the piece contains, for example, an index, nofollow, I want to close this connection and continue with the rest.
var host = 'example.com',
total = '',
http = require('http');
var req = http.request({hostname: host, port: 80, path: '/'}, function(res) {
res.on('data', function(chunk) {
total += chunk;
if(chunk.toString().indexOf('index,nofollow') == -1) {
} else {
}
}).on('end', function() {
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
The only thing I can not understand is to get out of this connection. Or stop receiving data because I do not need it.
req.end (); doesn't work .. it keeps on getting data / chunks .. (in my test I get 14 chunks, but in the first fragment I already know that I donβt need other chunks, so I want to exit the request / response).
Now I have a boolean that skips the analysis of the remaining blocks, but, in my opinion, should I skip data extraction?
? , ?