Skip to content

Instantly share code, notes, and snippets.

@kulor
Created May 8, 2012 11:55
Show Gist options
  • Save kulor/2634447 to your computer and use it in GitHub Desktop.
Save kulor/2634447 to your computer and use it in GitHub Desktop.
Send off multiple http requests and deal with response
var async = require('async'); // npm install async
async.parallel({
foo: function(callback){
http.get({host:'localhost', port:9999, path:'/foo'}, function (res) {
res.on('data', function (data) {
callback(null, JSON.parse(data.toString()));
});
})
},
bar: function(callback){
http.get({host:'localhost', port:9999, path:'/bar'}, function (res) {
res.on('data', function (data) {
callback(null, JSON.parse(data.toString()));
});
})
},
},
function(err, results){
res.render('template', {
foo: results.foo,
bar: results.bar
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment