Skip to content

Instantly share code, notes, and snippets.

@lk321
Last active November 27, 2018 18:39
Show Gist options
  • Save lk321/2a504b86279aaf1808805440878df856 to your computer and use it in GitHub Desktop.
Save lk321/2a504b86279aaf1808805440878df856 to your computer and use it in GitHub Desktop.
Import files with index
const path = require('path');
require('fs').readdirSync(__dirname).forEach((file) => {
/* If its the current file ignore it */
if (file === 'index.js') return;
const MODULE = require(path.join(__dirname, file));
module.exports[path.basename(file, '.js')] = MODULE.default || MODULE;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment