Last active
August 29, 2015 14:07
-
-
Save andreaj8/73a41d1e362eda3f88fd to your computer and use it in GitHub Desktop.
Node js, Series of http request synchronous
This file contains 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 request = require('request'); | |
var async = require('async'); | |
var array = []; | |
for (var i = 0; i < 10; i++) { | |
array.push(function (callback) { | |
request('www.google.com', function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
console.log("Primo body", body) // Print the google web page. | |
callback(null, body); | |
} | |
}) | |
}); | |
} | |
async.series(array, | |
// optional callback | |
function (err, results) { | |
// results is now equal to ['one', 'two'] | |
console.log("Resps", results) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment