mod.js
A Rust inspired utility tool for loading modules from a directory. Much like the
mod.rs
file that handles the repsonsibility or exporting modules inside a directory, mod.js
attempts to take on a similar responsibility with minimal overhead.
Getting Started
First, install through npm
npm install --save mod.js
Then, just require:
ES5
var load = require('mod.js');
ES6
import load from 'mod.js';
Examples
load
Given the directory
├ schemas/
│ ├ index.js
│ ├ person.js
│ ├ house.json // Supports .js and .json
├ index.js
Then in your schemas/index.js
file, you can simply
// ES5var load = ; moduleexports = ; --- // ES6; __dirname;
And then it's as easy as
// root index.jsvar schemas = ;// {// person: { ... },// house: { ... }//}
loadAsync
There is another function, loadAsync
, that will load the files asynchronously and return a promise.
Given the same directory as above, your schemas/index.js
file should look something like:
// ES5var loadAsync = loadAsync; moduleexports = ; --- // ES6 ; __dirname;
And once again:
// root index.js ;