Created
February 27, 2016 14:47
-
-
Save PatrickHeneise/910c5b8e4570304fb5b9 to your computer and use it in GitHub Desktop.
requirable index.js file to return an array of all .js and .json files within a directory
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'; | |
var fs = require('fs'); | |
var contents = []; | |
var files = fs.readdirSync(__dirname); | |
files.reduce(function (error, key) { | |
var file = key.replace(/.json|.js/g, ''); | |
if (file !== 'index') { | |
contents.push(require('./' + key)); | |
} | |
}); | |
module.exports = exports = contents; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
put all .json files into a data folder and add the index.js from above.