Skip to content

Instantly share code, notes, and snippets.

@rxw1
Created May 30, 2015 01:56
Show Gist options
  • Save rxw1/2b253ca56d1b44ee7627 to your computer and use it in GitHub Desktop.
Save rxw1/2b253ca56d1b44ee7627 to your computer and use it in GitHub Desktop.
Require all javascript files in a directory and export them by their file name
'use strict';
let fs = require('fs');
let path = require('path');
function excludeFiles(file) {
return (file.indexOf('.') !== 0) &&
(file !== 'index.js');
}
function exportFiles(file) {
let f = path.basename(file, '.js');
exports[f] = require('./' + f);
}
fs.readdirSync(__dirname)
.filter(excludeFiles)
.forEach(exportFiles);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment