title: making API calls blocking with nodejs
body: <p>I'm not sure if this is the right way to do this, but I am looking to make 10 API requests in a for loop, and I want every API request to be blocking. That is, to wait until I receive the response without going to a callback and then iterating over the foor loop again. Here is the foor loop</p>
  
  <pre><code>for (var i=0; i&lt; out.items.length; i++) {
      var object = makediffbotAPIcall(out.items[i]);
      console.log(object);
  }
  </code></pre>
  
  <p>The request function is the following </p>
  
  <pre><code>function makediffbotAPIcall(item, array) {
      var url_to_send_diffbot = "string of url here";
  
      request(url_to_send_diffbot, function (error, response, body) {
          if (!error &amp;&amp; response.statusCode == 200) {
              var article_object = JSON.parse(body)       
              var object = {"Title": article_object.title, "Url":article_object.url};
          }
  
      });
  
      return object;
  }
  </code></pre>
  
  <p>The problem with this code is that object doesn't return in time for the foor loop to make use of it. I tried putting a setTimeout at the end of the makediffbotAPIcall function, but that didn't work either. Any suggestions are much appreciated. Thanks! </p>