Created
December 21, 2013 15:48
-
-
Save sclarson/8071067 to your computer and use it in GitHub Desktop.
nodeschoo.io's http collect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var http = require('http'); | |
| var total = 3; | |
| var result = new Array(); | |
| function decrementAndPrint(element, data){ | |
| result[element] = data; | |
| total -= 1; | |
| if (total == 0){ | |
| console.log(result[0]); | |
| console.log(result[1]); | |
| console.log(result[2]); | |
| } | |
| } | |
| function processPage(index, url){ | |
| http.get(url,function(res){ | |
| res.setEncoding('utf8'); | |
| var characters = ''; | |
| res.on('data', function(data){ | |
| characters += data | |
| }); | |
| res.on('end', function(data){ | |
| decrementAndPrint(index,characters); | |
| }); | |
| }); | |
| } | |
| processPage(0,process.argv[2]); | |
| processPage(1,process.argv[3]); | |
| processPage(2,process.argv[4]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment