Skip to content

Instantly share code, notes, and snippets.

@richmarr
Created August 3, 2011 09:04
Show Gist options
  • Save richmarr/1122217 to your computer and use it in GitHub Desktop.
Save richmarr/1122217 to your computer and use it in GitHub Desktop.

Revisions

  1. richmarr revised this gist Aug 3, 2011. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,15 @@
    /*
    I found it handy to reduce the amount of requires in a complex
    I found it handy to reduce the amount of manual require() lines in a big
    project by grouping small modules together like below.
    If you put this code into "index.js" then it'll pick up any other
    JS modules in that directory and expose them as sub-modules.
    - Any exports in *this* module would be myPackage.exportName
    - Any exports in other modules would be myPackage.moduleName.exportName
    I use this for things like grouping controllers together, e.g.
    controllers.whateverController.methodName
    */

    var fs = require('fs');
  2. @invalid-email-address Anonymous created this gist Aug 3, 2011.
    19 changes: 19 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    /*
    I found it handy to reduce the amount of requires in a complex
    project by grouping small modules together like below.
    If you put this code into "index.js" then it'll pick up any other
    JS modules in that directory and expose them as sub-modules.
    - Any exports in *this* module would be myPackage.exportName
    - Any exports in other modules would be myPackage.moduleName.exportName
    */

    var fs = require('fs');

    // Read in the libs from this directory and add them as exports
    // This way you can just reference
    fs.readdirSync('./lib/auth').forEach(function(file){
    if ( file.indexOf(".js") > -1 && file != "index.js" )
    exports[ file.replace('.js','') ] = require('./'+file);
    });