Installation
$ npm install call-dir
Usage
import load, { loadAll } from "call-dir";
load(directory, callback);
loadAll(directory, callback);
Examples
Basic loading
import path from "path";
import load, { loadAll } from "call-dir";
const models = path.resolve(__dirname, "./path/to/models");
const routes = path.resolve(__dirname, "./path/to/routes");
load(models, (fpath, fname) => {
console.log(`Found file: ${fname} (absolute path: ${fpath})`);
});
load(models, (fpath) => require(fpath)(some, variables, ...here));
load(routes, (fpath) => require(fpath)(some, variables, ...here));
Deep loading
import path from "path";
import load, { loadAll } from "call-dir";
const modules = path.resolve(__dirname, "../node_modules");
loadAll(modules, (fpath, fname) => );
load(modules, (fpath, fname) => , true);
Tests
$ npm test