Load all files matching a regex and performs a callback on them.
Bulk Loader is a node.js module that can load all files in a given directory with filename matching a regular expression pattern. You can also pass a callback to be run when matching files are loaded.
path: sets the base path where the script should start looking, this is required when loading from path other than the app root dir
filepath: can be a file name or a path to a directory pattern: regex pattern to filter the files. eg: /Model.coffee$/i callback: call back will be run on each file
filepaths: an array of dir (reference: loadDir.dir) pattern: regex pattern to filter the files. eg: /Model.coffee$/i callback: call back will be run on each file
err: Error object with a message file: The required file filename: The filename
$ npm install bulk-loader
Let's imagine you have the follow directory structure for your project
$ lsangular app.js config node_modules public routes testapp.coffee bootstrap models package.json README.md scripts views$ ls models/picturesModel.js restaurantsModel.js reviewsModel.js usersModel.jspicturesSchema.js restaurantsSchema.js reviewsSchema.js usersSchema.js
You want to load all the Model.js files in app.js and call init method
bulkloader = require"bulk-loader"if err console.logfilename + " failed to load.\n" + errfileinit// loading model filesbulkloaderload"models" /Model\.js$/ loadModelCallback