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

lz-mod-manager

v1.1.7

Published

JSON module manager/loader for node.js npm packages

Downloads

6

Readme

Module Manager

Module Manager reads a JSON file and loads your Node.js modules into a single variable

Use

The module manager will create a folder called mod-loader in your projects root directory (same folder as node_modules). Inside are two files, mm-modules.json and schema.json

schema.json is only a reference to formatting mm-modules.json correctly.

mm-modules.json is read by Module Manager and loads the corresponding modules in order.

Configuring the JSON file

schema.json:

{
    "<module_var>": {
        "pkg": "<module-pkg-name>",
        "args": [],
        "data": [],
        "init": [],
        "last": []
    }
}

Property Explanation

  • <module_var>: The name of the variable used to access the module
var <module_var> = require('some-package')
  • pkg: The module name used for require
require('pkg')
  • args: Arguments to be appeneded to require
require('pkg')(args[0]).args[1]()...(args[n])
  • data: Optional data to be passed with constructor

  • init: JavaScript to be ran after this module has been loaded

  • last: JavaScript to be ran after all modules have been loaded. Executes in bottom-up order.

Accessors

Accessors are keywords used in the init (and last, but only mods) property of the JSON file to make changes to and read from objects that have been created.

  • mods: Access to modules that have been loaded (i.e. modules higher up the list) and ability to create new variables here. The module returns this object on completion as the result of the require().

  • data: Access to the data variable (if it exists) of the module being loaded.

  • pkg: The result of the require() function for the module being loaded.

Modifiers

Modifiers change the way the data is read from the JSON file.

  • &: Do not try to evalue JavaScript for this field.

Example mm-modules.json

{
    "express": {
        "pkg": "express",
        "init": [
            "mods.app = pkg();"
        ],
        "last": [
            "mods.app.listen(8000, (err) => { err ? console.log(err) : console.log('Listening on port 8000') })"
        ]
    },
    "session": {
        "pkg": "express-session",
        "data": [
            {
            "name": "session",
            "secret": "&blowfish",
            "resave": "&true",
            "saveUninitialized": "&false",
            "cookie": {
                "domain": "localhost",
                "httpOnly": "true",
                "secure": "false"
            }
        }],
        "init": [
            "mods.seshOpts = data"
        ],
        "last": [
            "mods.app.use(pkg(mods.seshOpts));"
        ]
    },
    "mySQLStore": {
        "pkg": "express-mysql-session",
        "args": ["(mods.session)"],
        "data": [{
            "host": "192.168.1.200",
            "port": "3306",
            "user": "test",
            "password": "password",
            "database": "db"
        }],
        "init": [
            "mods.sqlStore = new pkg(data);",
            "mods.seshOpts.store = mods.sqlStore"
        ]
    },
    "bodyParser": {
        "pkg": "body-parser",
        "init": [
            "mods.app.use(pkg.urlencoded({extended: true}));"
        ]
    },
    "util": {
        "pkg": "util"
    },
    "pug": {
        "pkg": "pug",
        "init": [
            "mods.app.set('view engine', 'pug');",
            "mods.app.set('views', './views');"
        ]
    },
    "pm": {
        "pkg": "./pm",
        "args": [
            "(mods)"
        ]
    }
}

Result

If you included the module using the standard method:

const modManager = require('lz-mod-manager');

The variable modManager becomes an object whose child elements are the modules and any objects attached to the mods modifier through the init or last properties.

Another method for easier access to modules is to wrap the require() in a with() statement like so:

with(modManager = require('lz-mod-manager')){
    app.get('/' function (req, res){
        res.sendStatus(200);
    });
}

Now all modules can be access by the <module_var> given in the JSON file