Last active
May 30, 2018 20:53
-
-
Save vladyslav-dotsenko/f647130878e492373a72efc5f6556574 to your computer and use it in GitHub Desktop.
NodeJS sample of `index.js` file that wraps all sibling files in a folder
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 trimName = filename => filename.replace(/\.(js|json)$/i, ''); | |
const modules = require("fs") | |
.readdirSync(__dirname) | |
.map((file) => [trimName(file), require("./" + file)]); | |
module.exports = modules.reduce((acc, module) => { | |
acc[module[0]] = module[1]; | |
return acc; | |
}, {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment