node.js calling multiple web services in parallel

http://askhds.blogspot.co.uk/2012/02/nodejs-rest-call-using-http-library.html

var http = require('http');
// Add helloworld module
var helloworld = require('helloworld_mod');

http.createServer(function(req, res) {

  res.writeHead(200, {
    'Content-Type' : 'text/xml'
  });

  try {
    // Bypass function call to "Google Maps API"
    getFromGoogle(req, res);
  }

  catch (e) {
    res.end("Try again later");
  }

}).listen(1337, '127.0.0.1');

console.log('Server running at http://127.0.0.1:1337/');

console.log('Type the URL in address bar');
console.log('http://127.0.0.1:1337/maps/api/geocode/xml?' 
+ 'address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false');

function getFromGoogle(mainreq, mainres) {
  // http://maps.googleapis.com/maps/api/geocode/
  // xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true_or_false

  var options = {
    host : 'maps.googleapis.com',
    port : 80,
    path : mainreq.url,
    method : 'GET'
  };

  var req = http.request(options);
  var result = '';

  req.on('response', function(response) {
    response.setEncoding('utf8');
    response.on('data', function(chunk) {
      result += chunk;
    });

    response.on('end', function() {
      mainres.end(result);
    });
  });

  req.on('error', function(e) {
    console.log('problem with request: ' + e.message);
  });

  req.end();
}

http://stackoverflow.com/questions/19273700/how-to-sync-call-in-node-js

var array = [1, 2, 3];
var data = 0;
var cntr = 0;

function countnExecute() {
    if (++cntr === array.length)
        executeOtherFunction(data);
}

for(var i = 0; i < array.length; i++){
    asyncFunction(data++, countnExecute);
}