0.0.2 • Published 9 years ago

panthera-loader v0.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

panthera-loader

npm Build Status Coverage Dependency Status Supported Node.js version MIT licensed

An auto-loading utility for Node.js modules.

Installation

npm install panthera-loader

Usage

const load = require('panthera-loader');

let sharedDependency = {};
let routes = {};

load(path.join(__dirname, './routes'), function(name, module) {
  routes[name] = module(sharedDependency);
}).then(function(results) {
  // `routes` is now populated with each module in `./routes`
  // `results` is an array of filenames of the modules that were loaded
});

load accepts two arguments, a file path and a callback function. Every JavaScript file in the directory, except for index.js, will be required by the module and passed to the callback function along with the name of the file (without the .js extension). The function returns a Promise that resolves to an array of the filenames that were loaded.