title: Node.js how to _.each internal callbacks synchronously
body: <p>I'm fairly new to node.js, and I can't figure out how to control the program flow so that my function waits for an Underscore _.each() block with internal callbacks. I'd really like to avoid a heinous callback stew. This block is in a chain already controlled by nimble's .series([]) </p>
  
  <pre><code>function (callback) { //get common friends    
      _.each(User.friends, function (friend) { //I NEED THE FLOW TO WAIT TIL THIS COLLECTION HAS ITERATED AND ALL THE CALLBACKS ARE COMPLETE
          request.get({
              url: 'https://graph.facebook.com/me/mutualfriends/' + friend.id + '?access_token=' + User.accessToken,
              json: true
          }, function (error, response, body) { //NEED TO WAIT TIL THESE ARE ALL COMPLETED
              if (!error &amp;&amp; response.statusCode == 200) {
                  console.log("common friends", body.data);
  
              } else {
                  console.log(error);
              }
          });
  
      }, this);
  
      callback(); //Nimble's serialization callback fires immediately
  },
  </code></pre>
  
  <p>I've tried a suggestion below to use async.each, but I can't get the iteration completion callback to fire, to tell nimble's .series function to continue to the next block.</p>
  
  <pre><code>async.each(User.friends, function(friend) {
          request.get({
          url: 'https://graph.facebook.com/me/mutualfriends/'+friend.id+'?access_token=' + User.accessToken,
          json: true
          }, function (error, response, body) { //NEED TO WAIT TIL THESE ARE ALL COMPLETED
              if (!error &amp;&amp; response.statusCode == 200) {
                  console.log("common friends",body.data);
  
              } else {
                  console.log(error);
              }
          });
  
  
      },function(err) {console.log('Final callback');callback();}); //THIS CALLBACK DOESN'T FIRE - NIMBLE JUST SITS AND WAITS
  </code></pre>