title: Compiling dynamically required modules with Browserify
body: <p>I am using Browserify to compile a large Node.js application into a single file (using options <code>--bare</code> and <code>--ignore-missing</code> [to avoid troubles with <code>lib-cov</code> in Express]).  I have some code to dynamically load modules based on what is available in a directory:</p>
  
  <pre><code>var fs = require('fs'),
      path = require('path');
  
  fs.readdirSync(__dirname).forEach(function (file) {
      if (file !== 'index.js' &amp;&amp; fs.statSync(path.join(__dirname, file)).isFile()) {
          module.exports[file.substring(0, file.length-3)] = require(path.join(__dirname, file));
      }
  });
  </code></pre>
  
  <p>I'm getting strange errors in my application where aribtrary text files are being loaded from the directory my compiled file is loaded in.  I think it's because paths are no longer set correctly, and because Browserify won't be able to <code>require()</code> the correct files that are dynamically loaded like this.</p>
  
  <p>Short of making a static <code>index.js</code> file, is there a preferred method of dynamically requiring a directory of modules that is out-of-the-box compatible with Browserify?</p>