
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
node-auto-loader
Advanced tools
Node Auto Loader provides a simple way to automatically load a directory of CommonJS (CJS) modules, ES6 (MJS) modules, and JSON files automatically.
Node Auto Loader (NAL) is a dependency free single file module auto loader. NAL is capable of automatically auto loading CommonJS (CJS) modules, ES6 (MJS) modules, and JSON files. You should consider using NAL if:
:heavy_check_mark: You have a lot of modules to require/import at once.
:heavy_check_mark: You want to modularize your application.
:heavy_check_mark: You want to automate a process; auto loading many Express routes or MongoDB schemas for example.
NAL can be installed with npm and will run in either CommonJS (CJS) or ES6 (MJS) projects. Add NAL as a dependency for your project with:
npm install node-auto-loader
NAL can be manually incorporated into your CommonJS projects by adding the auto-loader.js file into your project, and then requiring it where needed:
const AutoLoader = require('./auto-loader');
If you manually alter the auto-loader.js file and convert it into an ES6 (MJS) module, you can import it in ES6 projects:
import AutoLoader from './auto-loader.js';
NOTE: Manual installs are not recommended, use the automatic install instead to automatically receive updates.
NAL can be instantiated and run with various options. Here is a simple example of NAL being used to auto load modules from a fictional modules directory:
// CommonJS require:
const AutoLoader = require('node-auto-loader');
// OR ES6 import:
import AutoLoader from ('node-auto-loader');
// Get a new instance of AutoLoader and set it to load the modules directory.
const autoLoader = new AutoLoader('./modules');
/*
* Modules are automatically loaded then passed to a callback function. You can
* do whatever you need to in the callback function, like invoking a module, or
* nothing if you just needed the module to be loaded; this is always required!
*/
function callback(module) { ... }
/*
* Optional callback function that must return a true or false. This allows you
* to decide if a module should be auto loaded (true) or skipped (false).
*/
function checkModuleFirst(pathToModule) { ... }
// What options to use when loading modules. If missing defaults will be used.
const options = {
allowJSON: false,
checkFirst: checkModuleFirst,
recursive: true
}
/**
* Load the modules automatically. You do not need to capture the results
* unless you want to. The results object will let you know what was
* successfully auto loaded and what errors may have occurred.
*/
let results = await autoLoader.loadModules(callback, options);
setDirectory or the directory autoLoader was instantiated with.callback is required. If you only need modules to auto load and do not need to invoke anything else, callback can be an empty function.options is an object that allows you to alter the way loadModules works; see next section for more information.type can be either CJS for CommonJS modules or MJS for ES6 modules.pathToDir is a relative or absolute path to the directory to auto load.loadModules OptionsThe loadModules method accepts an optional options object. You can uses this object to alter the way loadModules works:
true if you would like autoLoader to also auto load JSON files for you.fs package, not required or import; this means they will not be cached.function that will be called before autoLoader attempts to load a module.filePath allowing you to determine if the module should be loaded (true) or not (false); must return a true or false value!false if you do not want the autoLoader to recursively load modules.false this will stop loadModules from recursively searching all directories under the configured directory for modules.The current changelog is here. All other changelogs are here.
NAL is an open source community supported project, if you would like to help please consider tackling an issue or making a donation to keep the project alive.
Reminder: Before submitting new pull requests make sure to run npm test. If you add a new feature make sure it is covered by a new or existing test.
FAQs
Node Auto Loader provides a simple way to automatically load a directory of CommonJS (CJS) modules, ES6 (MJS) modules, and JSON files automatically.
We found that node-auto-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.