title: Define module with dependencies for AMD (requirejs) and Common.js (Node.js) and global scope
body: <p>I'm trying to create a function that accessible with AMD, Common.js, and in the Global Scope. My one caveat is that it has dependancies. Require.js and global scope seem to be working fine but I can't get the dependencies to load in Node.js. </p>
  
  <pre><code>(function(global, factory) {
    // Node.js
    if (typeof exports === 'object' &amp;&amp; typeof module !== 'undefined') {
      moment = require('moment');
      return module.exports = factory();
  
    }
    // require.js
    else if (typeof define === 'function' &amp;&amp; define.amd) {
      return define(['moment'], function(moment) {
        global.moment = moment;
        return factory();
      });
    }
    // global
    else {
      return global.formatDate = factory();
    }
  })(this, function() {
  
    var formatDate = function(date, format) {
      if (typeof moment !== 'function' &amp;&amp; !moment) {
        console.error('moment is required to format date')
        return date;
      }
     return moment(date).format(format);
    };
  
    return formatDate;
  });
  </code></pre>