Skip to content

Instantly share code, notes, and snippets.

@jsscclr
Created July 25, 2015 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsscclr/c52daefd4ad3eb084dd9 to your computer and use it in GitHub Desktop.
Save jsscclr/c52daefd4ad3eb084dd9 to your computer and use it in GitHub Desktop.
// Collect the complete content of three URLs and print it to the console.
// Print one line per URL.
// Print out them out in the same order as the URLs are provided to you as command-line arguments.
var http = require('http');
var urls = [];
for (var i = 2; i < process.argv.length; i++) {
urls.push(process.argv[i]);
}
var strings = [];
function http_request (url, index) {
http.get(url, function (response) {
response.setEncoding('utf8');
var completeString = "";
response.on("data", function(data) {
completeString += data;
});
response.on("end", function() {
strings[index] = completeString;
if (urls.length == strings.length && strings[0]) {
for(string in strings) {
console.log(strings[string]);
}
}
});
});
}
for (url in urls) {
http_request(urls[url], url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment