title: Node.js - Wait for multiple async calls to finish before continuing in code
body: <p>So basically i have a for loop with an async function in it. Problem is that the program just continues after the loop and i want it to wait until all async functions which were called in the loop are finished before the code continues.</p>
  
  <p>In my code "bar" is a json array with other json arrays in it.</p>
  
  <pre><code>function write(bla) { // gets called one after another
  
    for(var url in bla) {
      asyncFunctionCall(url); // Executed about 50 times, it has to run parallel
    }
    // Wait for all called functions to finish before next stuff happens and
    // write gets called again.
  
  }
  
  for(var foo in bar) {
    // Here i parse the json array "foo" which is in the json array "bar"
    write(foo[bla]); // bla is an array of multiple urls.
  }
  </code></pre>
  
  <p>The async function call looks something like this:</p>
  
  <pre><code>var request = require('request');
  
  request(url, function (error, response, body) {
    if(typeof response !== 'undefined') {
      if((response.statusCode &gt;= 400 &amp;&amp; response.statusCode &lt;= 451)
      || (response.statusCode &gt;= 500 &amp;&amp; response.statusCode &lt;= 511))
        return true;
      return false;
    }
    return false;
  });
  </code></pre>