Skip to content

Instantly share code, notes, and snippets.

@sscovil
Last active September 17, 2016 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sscovil/04d91fb86a078beddae4c6693ed5fe83 to your computer and use it in GitHub Desktop.
Save sscovil/04d91fb86a078beddae4c6693ed5fe83 to your computer and use it in GitHub Desktop.
Node.js recipe for an index.js file that exports all other .js files in the same directory.
'use strict';
const fs = require('fs');
const JS_FILE = /^((?!(index)).)*\.js$/;
const JS_FILE_EXTENSION = /\.js$/;
fs.readdirSync(__dirname)
.filter(file => JS_FILE.test(file))
.forEach(file => exports[file.replace(JS_FILE_EXTENSION, '')] = require(`./${file}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment