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