title: Promises in bluebird to control function order
body: <p>I've been trying to understand promises for the server side for the last few days, but I've yet to find anything to work. <a href="https://github.com/petkaantonov/bluebird" rel="nofollow noreferrer">Bluebird</a> however seems to be a good alternative. Following the <a href="https://github.com/petkaantonov/bluebird/blob/master/API.md#thenfunction-fulfilledhandler--function-rejectedhandler----promise" rel="nofollow noreferrer">API</a> I've tried to test it out but I get an error of: "Cannot call method 'then' of undefined". I looked for <a href="https://stackoverflow.com/questions/22643061/i-broke-my-promise">similar</a> errors but I couldn't make mine work similarly.</p>
  
  <p>This is my attempt with bluebird so far:</p>
  
  <pre><code>var Promise = require('bluebird')
  var cheerio = require('cheerio');
  var request = require('request');
  
  // do I need this?
  // var request = Promise.promisify(require('request'));
  // Promise.promisifyAll(request);
  
  function getA() {
      $(path).each(function(i,e){
          link = $(this).attr("href");
          getB(...).then(function(urls) {
              console.log('type of urls: ' + typeof(urls) + urls);
              // getC();
          }).then(function(urls) {
              // getD();
          });
      });
  }
  
  function getB() {
      return new Promise(function(fullfill, reject) {
          request(selectedShow, function (err, resp, page) {      
              if (!err &amp;&amp; resp.statusCode == 200) {
                  var $ = cheerio.load(page);
                  $(path).each(function(i,e){
                      stuff.push($(this).text());
                  }
              }); // end each loop
          } // end error and status check
          fullfill(stuff);
      }); // end request
  }
  
  function getC() {
      // use 'stuff' array to make requests and fill another array
  }   
  
  function getD() {
      // use the arrays to build an object
  }
  </code></pre>