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 🙏

© 2026 – Pkg Stats / Ryan Hefner

enjection

v0.1.0

Published

Simple Dependency Injection

Readme

Dependency Injection

When developing across modules, dependencies are normally introduced by the require statement. This method has a drawback of tying the modules together by a specific relative (or even absolute) path, and makes testing more difficult since each module is tied to others.

There are existing Dependency Injection system out, however each one of them requires listing the necessary dependencies (usually by string) and then a number of references that the dependencies will be received in.

enjection solves this issue. New modules are defined as a function that accepts a dependency object, and dependencies are recursively resolved as they are accessed off the dependency object.

This means you can define what dependencies all of your modules will use based on whether you are in development, production, testing, or more. Also, each module does not need to know where another is to require it as a dependency.

Usage

When starting up an application, you only need to register new modules and then execute one. If a module is defined as an Enjection module, register is used. If a module is a standard module (ex. node_modules) the inject function is used. Finally, resolve is used to start resolving one of the modules.

entry.js

const { inject, register, resolve } = require('enjection');

inject('express', require('express'));
inject('http', require('http'));
inject('logger', require('some-logger'))

register('app', require('./app'));
register('createEndpoint', require('./create-endpoint'));

const server = resolve('app');

New modules are defined as either singletons or factories:

app.js

// Singleton module
module.exports = ({ express, http, createEndpoint })=> {
    const app = express();

    app.get('/', createEndpoint('Hello, Home Page!'));
    app.get('/contact', createEndpoint('Hello, Contact Page!'));
    app.get('/pricing', createEndpoint('Hello, Pricing Page!'));
    app.use((req, res)=> res.send('Not Found'));

    return http.createServer(app);
};

create-endpoint.js

// Factory module (just returns a function)
module.exports = ({ logger })=> (text)=> {
    return (req, res)=> {
        logger.info(text);
        res.send(text);
    };
};

Full API

inject(String name, Any module)
injectAll(Object modules)
register(String name, Func DIModule)
resolve(String name)
reset()