Skip to content

Instantly share code, notes, and snippets.

@cgrinker
Created April 13, 2019 18:21
Show Gist options
  • Save cgrinker/2e876d8248be4ad8f36180801e62eb52 to your computer and use it in GitHub Desktop.
Save cgrinker/2e876d8248be4ad8f36180801e62eb52 to your computer and use it in GitHub Desktop.
Export all files in a directory
const fs = require('fs');
module.exports = fs.readdirSync(__dirname )
.filter((e)=>{return e !== 'index.js'})
.map((e)=> {
return [e.split('.')[0], require(`./${e}`)]
})
.reduce((acc, val)=> {
acc[val[0]] = val[1];
return acc;
}, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment