title: Bluebird.js in Node and asynchronous api calls
body: <p>So I'm trying to build my first webapp with Facebook integration (using <a href="https://github.com/amachang/facebook-node-sdk" rel="nofollow">facebook-node-sdk</a>). I have it making simple calls to the api, but now it's time to put this all in a simple server and make the calls upon request (this isn't going to be the webapp, itself, but more of an API server).</p>
  
  <p>The problem I'm running into is that, even though I've (presumably) used <a href="https://github.com/petkaantonov/bluebird" rel="nofollow">bluebird</a> to Promisify the Facebook sdk and my <code>makeCall</code> method, I'm still getting "hi" printed and then "undefined" - <code>console.log</code> is getting called before makeCall can return anything.</p>
  
  <p>Here's my <code>app.js</code>:</p>
  
  <pre class="lang-js prettyprint-override"><code>var Promise = require('bluebird')
      , http = require('http')
      , Facebook = Promise.promisifyAll(require('facebook-node-sdk'))
      , config = require('./config')
      , fb = new Facebook({ appId: config.fb.api, secret: config.fb.secret });
  
  var makeCall = new Promise.method(function (username) {
      return fb.api(username, function(err, data) {
          console.log('hi')
          if (err) return err;
  
          return data;
      });
  });
  
  http.createServer( function (req, res) {
      makeCall('/me').then(console.log)
  }).listen(8001);
  </code></pre>