rf-load
- simple asynchron NodeJS module loading lib
- load single files, node modules, functions, or a complete directory
- all modules are collected in a list, then required and started one by one
- modules are kept in memory and can be accessed with a require() like function at any time
Getting Started
npm install rf-load
var load = newmoduleLoader; // get the modules //files load; load; // load moduledir/db.js load; // additional parameters // npm module load; // function load; // load a function // start modules one by oneload;
Or load all files in a directory parallel:
load; // place the above code in the module loader,// if it shoud be executed, after other module were loaded:load;
Module structure
- 'start' function necessary
- the start function calls the next module. If it fails, the module execution will not finish.
"use strict"; moduleexports { // ...do your module things // call the next module ;}
Accessing modules from other files
- modules can be accessed after loading with a special require function
- intention: main module loads and configures all required modules
- similar ro
require()
, but it throws an error if the module hasn't been loaded
var acl = ;// You can now access any module.exports variables and functions from the acl module
Conflicting module names
If you have modules with the same name in you .require() calls, define a prefix in front of each modules name.
For example two module directories:
- moddir1
- mod1.js
- mod2.js
- moddir2
- mod1.js
- mod2.js
Include them:
var load1 = newmoduleLoader"dir1.";load1;load1; var load2 = newmoduleLoader"dir2.";load2;load2;
Now require them individually with their prefix:
var moddir1_mod2 = moddir2_mod1 = ;
Legal Issues
- Licenese: MIT
- Author: Julian von Mendel