Skip to content

Instantly share code, notes, and snippets.

@andreaj8
Last active August 29, 2015 14:07
Show Gist options
  • Save andreaj8/73a41d1e362eda3f88fd to your computer and use it in GitHub Desktop.
Save andreaj8/73a41d1e362eda3f88fd to your computer and use it in GitHub Desktop.
Node js, Series of http request synchronous
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