title: Using recursive pattern loop with node.js
body: <p>ive been trying to use node.js to iterate through an array of cities and make an iterative request to google for directions on each (i then JSON.parse to abstract the drive times).  I need to find a way to do this synchronously as otherwise i will just be requesting all the info from google on each city at once.  I found a good pattern to use at <a href="http://tech.richardrodger.com/2011/04/21/node-js-%E2%80%93-how-to-write-a-for-loop-with-callbacks/">http://tech.richardrodger.com/2011/04/21/node-js-%E2%80%93-how-to-write-a-for-loop-with-callbacks/</a> but cannot get the callback to work.  As you can see, im using a 'show' function to test the same.  My code is as follows:</p>
  
  <pre><code>var request = require('request');
  var fs = require('fs');
  var arr = ['glasgow','preston','blackpool','chorley','newcastle','bolton','paris','york','doncaster'];
  //the function I want to call on each city from [arr]
  function getTravelTime(a, b,callback){
   request('https://maps.googleapis.com/maps/api/directions/json?origin='+a+'&amp;destination='+b+'&amp;region=en&amp;sensor=false',function(err,res,data){
   var foo = JSON.parse(data);
   var duration = foo.routes[0].legs[0].duration.text;
   console.log(duration);
   });
  };
  
  function show(b){
   fs.writeFile('testing.txt',b);
  };
  
  
  function uploader(i){
   if( i &lt; arr.length ){
     show( arr[i],function(){
     uploader(i+1);
     });
   }
  }
  uploader(0)
  </code></pre>
  
  <p>The problem I have is that only the first city from the array is output and the callback/iteration never proceeds.  Any ideas where im going wrong please?
   </p>