title: Node js - How to correctly use make async network calls within a module
body: <p>So for part of a project I am working on I have created a module that uses the Facebook graph API to make calls and return JSON data. I can console.log() the data within the method out fine and it's all good.</p>
  
  <p>But I can not return the values from the methods, so I tried to use the 'async' npm module. I have followed the examples on the website, but still am struggling to get everything working, spent all day on it so far and still things arn't looking any clearer.</p>
  
  <p><strong>So what I am asking is:</strong></p>
  
  <ul>
  <li>Firstly I need to call the method that sets the authentication_token for the fbgraph api before I can do anything else</li>
  <li>Then I need to call each of the functions (in any order) and get the json result for each and add it to one big json result</li>
  <li>Finally I need to get this one big json result back into my origional javascript page (even though it's currently in a module), how would I invoke it?</li>
  </ul>
  
  <p>Here is a snippit of my original module (only works with console.log, can't return)</p>
  
  <pre><code>module.exports = {
          /**
           * Pass the access token to the fbgraph module
           * and call other methods to populate
           */
           setUp: function (access_token) {
               graph.setAccessToken(access_token);
           },
  
          /**
           * Fetches users basic info:
           * Age, Gender, Hometown, Relationship status
           */
          getBasicInfo: function(){
              graph.get("/me/", function(err, res) {
                  var result = {
                      'age'       : _calculateAge(res.birthday),
                      'gender'    : res.gender,
                      'hometown'  : res.hometown.name,
                      'relationship_status' : res.relationship_status
                  };
                  //console.log(result);
                  return result;
              }, function(){ console.log("DONE");});
          },
          /**
           * Creates a body of text as a string
           * made up of all the users status updates
           */
          getPosts: function(){
              graph.get("/me/feed?limit="+PHOTO_LIMIT, function(err, res) {
                  var posts = "";
                  for(var i=0;i&lt;res.data.length;i++){
                      var obj = res.data[i];
                      if(obj.message!=undefined) posts += obj.message+"\n";
                  }
                  //console.log(posts);
                  return {'posts':posts};
              });
          },
          /**
           * Fetches a single dimension string array of
           * photos user is tagged in
           */
          getPhotos: function(){
              graph.get("/me/photos?limit="+PHOTO_LIMIT, function(err, res) {
                  var photos = [];
                  for(var i=0;i&lt;res.data.length;i++){
                      var obj = res.data[i];
                      photos.push(obj.source); // .source is full size image, .picture is a thumbnail
                  }
                  return {'photos': photos};
              });
          }
       }
  </code></pre>
  
  <p>The rest of this module continues in a similar way 
  I have tried using parralel async</p>
  
  <pre><code>module.exports = {
      getFacebookInfo: function (access_token) {
          results = {};
          setUp(access_token);
          async.parallel([
              facebookDataRequests.getBasicInfo(),
              facebookDataRequests.getPosts()
  </code></pre>
  
  <p>Any guidence on how I should structure this would be very much appreciated, thanks in advance</p>