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

naughty-loader

v0.1.4

Published

Nodejs module loader, ID containerization

Readme

Naughty Loader

license snyk npm version NPM Downloads NPM Downloads

Loader doesn't support top level awaits due to using require as module loader

Formats

  • js

  • mjs

  • cjs

  • json

  • ts - use with caution
    will cause errors when trying to load .ts file in js environment
    but works with some npm libraries like nodemon.

API

Npm packages

Node lib

Single files

  • With dependency injection (by default)
  • Without dependency injection

Module directory

directory contains files that will be part of aggregated api

  • With dependency injection (by default)
  • Without dependency injection

Directory

directory with modules directories

  • With dependency injection (by default)
  • Without dependency injection

Root file

directory contains only index.(m|c)js will be unwrapped and become only thing that loader will return

  • With dependency injection (by default)
  • Without dependency injection

Types

interface NpmOptions {
omit?: string[];
rename?: Record<string, string>;
}

type ArrayLike = { length: number, includes(item: any): boolean };

interface LoadOptions {
context?: any;
loadOnly?: ArrayLike;
}

interface FileOptions {
context?: any;
loadOnly?: boolean;
}

interface DirOptions {
shared?: LoadOptions;
options?: Record<string, LoadOptions>;
}

type Npm = (path: string, options?: NpmOptions) => Readonly<Record<string, Readonly<any>>>;
type Node = (modules: string[]) => Readonly<Record<string, any>>;
type Module = (path: string, context?: LoadOptions) => Readonly<Record<string, any>>;
type Dir = (path: string, context?: DirOptions) => Readonly<Record<string, Readonly<any>>>;
type NoDI = () => any;
type Root = (path: string, context?: LoadOptions) => any;
type File = (path: string, context?: FileOptions) => any;

Examples

Node

const libs = ['http', 'worker_threads', 'path', 'events'];

const node = loader.node(libs);
const PORT = 3000;
const server = node.http.createServer(() => {
  //...
});
server.listen(PORT);

const { EventEmitter } = node.events;
class A extends EventEmitter {
  constructor(){
    super();
  }

  method(){
    this.emit("method");
  }
}
const a = new A();
a.method();

Npm

const packageJson = path.resolve('package.json');
const options = { // optional
  omit: ['ws', 'prisma'], 
  rename: { pg: 'postgres', 'naughty-util': 'util' },
};
const npm = loader.npm(packageJson, options);
const config = { pg: {},};
const pool = new npm.postgres.Pool(config.pg);
await pool.connect();

const readFile = npm.util.async.promisify(fs.readFile);
const file = await readFile(__filename, "utf-8");
console.log(file);

Module

`
  └── src/
      └── test/
          ├── method.js
          ├── di_module.mjs
          └── primitive.cjs
`
const options = {
  context: { 
    smth: {
      method(){
        console.log("Injected");
      }
    }
  },
  loadOnly: ["method"],
};
// path -> .../src/test
const api = loader.module(path, options);

/* if file exports a function, loader will call it injecting context, 
use loadOnly: ['name'] to prevent it */
// file content -> export default () => console.log("method");
// output -> console.log("method")
const output = api.method(); 

// file content -> 
`export default (context) => ({
  di_method(){
    return  context.smth.method();
  }
});`
// output -> console.log("Injected")
const di = api.di_module.di_method();

// file content -> module.exports = 'primitive';
// value -> 'primitive';
const primitive = api.primitive;

Dir

`
  └── src/
      └── test/
          ├── method.js
          ├── di_module.mjs
          └── primitive.cjs
`
const dirOptions = {
  options: {
    test: { // specific folder
      context: { 
        smth: {
          method(){
            console.log("Injected");
          }
        }
      },
      loadOnly: ["method"],
    },
    shared: { // shared among all folders 
      context: { 
        smth: {
          method(){
            console.log("Injected");
          }
        }
      },
      loadOnly: ["method"],
    }
  },
};
/* here we load test folder, it leads us 
to use loader.module to all sub folders in test folder */

// path -> .../src
const api = loader.dir(path, dirOptions);

/* if file exports a function, loader will call it injecting context, 
use loadOnly: ['name'] to prevent it */
// file content -> export default () => console.log("method");
// output -> console.log("method")
const output = api.test.method();

// test folder api reminds the same as above 

Root

  `
    └── src/
        └── test/
            ├── index.js
            └── folder
                └── file.json
  `
  const options = {
    context: { test: 42 },
    loadOnly: true,
  };
  /* it will ignore everting but index.(m|c)js file, first it will find*/
  // file context module.exports = () => console.log('test');
  // path -> .../src/test
  const api = loader.root(path, options);
  // since we have onlyLoad = true; it will result in console.log('test') output;
  api(); 

File

  `
    └── src/
        └── file.js
  `
  const options = {
    context: { test: 42 },
  };
  /* loads one file */
  // file context export default () => console.log('test');
  // path -> .../src/file.js
  const api = loader.file(path, options);
  // it exports a function and we don't use onlyLoad option here 
  // loader will call function and inject { test: 42 } context like a fn parameter
  console.log(api); // undefined
  api(); // error

Part of naughty stack