npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rf-load

v0.1.13

Published

Simple NodeJS module loading lib

Downloads

4

Readme

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 = new(require("rf-load").moduleLoader)();

// get the modules

//files
   load.setModulePath("moduledir");
   load.file("db"); // load moduledir/db.js
   load.file("acl", { parameters: 123 }); // additional parameters

// npm module
   load.module("web", { parameters: 123 });

// function
   load.func(function (options, next) {
      console.log("I am a function " + options.whatami);
      next();
   }, { whatami: "without name" } ); // load a function


// start modules one by one
load.startModules();

Or load all files in a directory parallel:

load.getDirectoryPaths('./server/api').forEach(function(path){
   // start each file with specific arguments
   require(path).start(dataBase, app);
});

// place the above code in the module loader,
// if it shoud be executed, after other module were loaded:
load.func(function (options, next) {
   load.getDirectoryPaths('./server/api').forEach(function(path){
      require(path).start(dataBase, app);
   }); next();
});

Module structure

  • 'start' function necessary
  • the start function calls the next module. If it fails, the module execution will not finish.
"use strict";

module.exports.start = function (options, next) {
   // ...do your module things

   // call the next module
   next();
}

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 = require("rf-load").require("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 = new(require("rf-load").moduleLoader)("dir1.");
load1.moduleDirectory("moddir1");
load1.startModules();

var load2 = new(require("rf-load").moduleLoader)("dir2.");
load2.moduleDirectory("moddir2");
load2.startModules();

Now require them individually with their prefix:

var moddir1_mod2 = require("rf-load").require("dir1.mod2"),
    moddir2_mod1 = require("rf-load").require("dir2.mod1");

Legal Issues

  • Licenese: MIT
  • Author: Julian von Mendel