zilcuanu
zilcuanu

Reputation: 3715

Nodejs making parallel http calls and consolidate the result

I am new to using Nodejs. How to make multiple http calls in parallel and send consolidate response.

Regards, Pradeep

Upvotes: 0

Views: 281

Answers (1)

user1695032
user1695032

Reputation: 1142

You can use async module. This is from https://github.com/caolan/async

// an example using an object instead of an array
async.parallel({
    one: function(callback){
        setTimeout(function(){
            callback(null, 1);
        }, 200);
    },
    two: function(callback){
        setTimeout(function(){
            callback(null, 2);
        }, 100);
    }
},
function(err, results) {
    // results is now equals to: {one: 1, two: 2}
});

Upvotes: 1

Related Questions