Skip to content

Instantly share code, notes, and snippets.

@jaceju
Last active December 19, 2018 02:55
Show Gist options
  • Save jaceju/4421dd4fd46bc9f2c249f2e614830931 to your computer and use it in GitHub Desktop.
Save jaceju/4421dd4fd46bc9f2c249f2e614830931 to your computer and use it in GitHub Desktop.
Export modules under a directory (Node.js)
const camelCase = require('camelcase');
require('fs').readdirSync(__dirname + '/').forEach(file => {
if (file.endsWith('js') && file !== 'index.js') {
var name = file.replace('.js', '');
exports[camelCase(name)] = require('./' + file);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment