title: making api calls in sync in nodejs
body: <p>My code is something like this:</p>
  
  <pre><code>for(let query of array1){ 
     request.get(query, function(err, res, body){
       var array2 = body
       for (let query2 of array2){
          request.get(query, function(err, res, body){
              var variable1 = body
              updateDB(query, query2 , variable1)
           });
       }
     });
  }
  </code></pre>
  
  <p>suppose Array1 is [1,2,3,4]</p>
  
  <p>with first loop array2 will [a,b,c,d](and second loop will give [e,f,g,h] and so on).</p>
  
  <p>Now my updateDB just updates for first value of array2[in above case just for a and e] in each loop. where as i want it to loop through all the elements of array2(like b, c, d) before it moves to second set of array2(i.e [e,f,g,h]).</p>
  
  <p>I know this is happening because of async nature of js. But how can i fix it? How can I make outer loop to wait for inner loop to finish?</p>
  
  <p>Hope so I am clear enough. Thanks In advance!!</p>