Monday, 23 October 2017

Troubleshoot NodeJS script to pull HTML?

Hi can you guys help me troubleshoot this script?We are pulling the HTML status of different IPs but for some reason I get quite a few "001|undefined" results and I cant figure out why.. 001|undefined 001|undefined 001|undefined 001|undefined 001|undefined 303|173.21.42.45 303|152.215.152.123 303|133.20.52.111 var http = require('http'); var fs = require('fs') var ipArray; fs.readFile('PowerControllerIP.txt', 'utf8', function(err, data) { if (err) throw err; ipArray = data.split("\n"); for(i = 0; i < ipArray.length; i++){ var x = ipArray[i]; var req = http.get("http://"+ipArray[i], function(res,err) { console.log(res.statusCode + "|" + this.ipStr); }.bind({ipStr: x})).on('error', function(e) { console.log("001|" + e.address); }); req.setTimeout(30000, function(){ console.log("TimeOut|" + this.ipStr); }.bind({ipStr: x})); } });

Submitted October 23, 2017 at 01:38PM by UpYourQuality

No comments:

Post a Comment