Skip to content

Instantly share code, notes, and snippets.

@vladyslav-dotsenko
Last active May 30, 2018 20:53
Show Gist options
  • Save vladyslav-dotsenko/f647130878e492373a72efc5f6556574 to your computer and use it in GitHub Desktop.
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
'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