I have written this function. What it does is reading recursively all the files into a folder thanks to nodejs module recursive-readdir. It works well.
The problem is I don't know how to export outside routes
array by using module.exports
. I have tried to put it outside the callback function, inside but the variable is undefined. Any idea?
var path = require('path');
var recursive = require('recursive-readdir');
recursive(__dirname, function(err, files){
var routes = {};
for (var i = 0, dim = files.length; i < dim; i++) {
var file = path.basename(files[i], '.js');
if(file !== 'bootstrap'){
routes[file] = require(files[i]);
}
}
});