title: Is providing a Promise as a module's export a valid pattern for asynch initialization in Node.js?
body: <p>I need to write some modules that load data one time and then provide an interface to that data.  I'd like to load the data asynchronously.  My application already uses promises. Is providing a promise as the result of requiring a module a valid pattern/idiom?</p>
  
  <p>Example Module:</p>
  
  <pre><code>var DB = require('promise-based-db-module');
  
  module.exports =
    DB.fetch('foo')
    .then(function(foo){
      return {
          getId: function(){return foo.id;},
          getName: function(){return foo.name;}
      };
    });
  </code></pre>
  
  <p>Example Usage:</p>
  
  <pre><code>require('./myPromiseModule')
  .then(function(dataInterface){
    // Use the data
  });
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>I've used this for a while now and it works great. One thing I've learned, and it's hinted at in the accepted answer, is that it is good to cache the promise itself, and whenever you want to access the data use <code>then</code>. The first time the data is accessed, the code will wait until the promise is resolved.  Subsequent usage of <code>then</code> will return the data immediately. e.g.</p>
  
  <pre><code>var cachedPromise = require('./myPromiseModule');
  cachedPromise.then(function(dataInterface){
    // Use the data
  });
  ...
  cachedPromise.then(function(dataInterface){
    // Use the data again somewhere else.
  });
  </code></pre>