A library to load all files as modules based on glob syntax.
A node.js library to find and load files as modules based on glob file syntax (i.e. 'plugins/*/.js').
var loader = require'glob-module-loader';// a single path with a single callback once all modules are loadedloaderload'plugins/**/*.js'console.log'Loaded %s' moduleslength;;// multiple paths and a callback that should be called for each module loadedloaderload'plugins/**/*.js' 'vendor/**/*.js'console.log'Loaded a module';console.log'Loading complete';;
glob-module-loader can be easily installed using npm.
npm install glob-module-loader
Then simply require glob-module-loader in your application
glob-module-loader is intended to find all files matching a glob syntax (i.e. "plugins/*/.js") and load each file as an individual module. It can load all modules synchronously and hand back an array, or it can load them asynchronously calling a callback method for each module loaded.
var loader = require'glob-module-loader';// load synchronouslyloaderload'plugins/**/*.js'console.log'Loaded %s' modules moduleslength;;// load asynchronouslyloaderload'plugins/**/*.js'console.log'Called for each module loaded';console.log'Loaded %s' modules moduleslength;;
glob-module-loader depends on the following packages:
Searches the file system for modules to load based on the glob patterns provided. Once all modules have been loaded the callback function is called passing the loaded modules as an array.
- patterns - A string or array of strings containing glob patterns to search.
- module_callback(module) - An optional callback function which is called for each module immediately after it is loaded.
- callback(err, modules) - A callback which is called after all modules have been loaded, or until an error is encountered. If an error is encountered the callback will be called immediately and no modules will be returned.
loaderload'*.js' 'dir/*.js'// all modules loaded are now in the modules array;loaderload'*.js' 'dir/*.js'// called for each module// all modules loaded are now in the modules array;