Last active
September 17, 2016 23:43
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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