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 🙏

© 2025 – Pkg Stats / Ryan Hefner

node-module-context

v1.2.5

Published

Works on node.js version 8.x doesn't works on older versions.

Downloads

13

Readme

Node Module Context

Works on node.js version 8.x doesn't works on older versions.

This is a module that intends to fix some concurrency issues by contextifying core module system and not spawning child processes. It does this by executing your module and every other module you required in a desired context by instantiating a new module provider(lib/module.js basically). With this you could have multiple module providers executing your code in parallel in an controlled environment without mixing with each other.

Attention!

This module uses undocumented api (process.bindings). While there is a discussion about removing it ( see the closed github issue ) it seems it's advised against(too many packages already using it) or at worst case a flag will be introduced but it's still better to be informed.

Example

const contextify = require("node-module-context");

const execute = contextify("path/to/your/file", options);

const myExportedModule = execute(context);

Pros

  • Request isolation - more fault tolerant applications ( less chance to mess the rest of the app if something goes wrong with a single request).
  • Especially on isomorphic applications you don't have to think twice about concurrency. You can just import your state machine and no other request can temper with it.

Cons

  • Every time you execute your code everything it depends on read from disk and interpreted by v8 (pre compile too if you included the option). On the first time of execute all of these steps are cached but interpreting remains. Which means it can get a little slow the first time but be assured I am preloading non npm modules at the moment for cache and preloading for npm modules are on the way. So might want to consider the interpreting time.

Options

preCompiler: function

A function with a single argument "source". You will be required to return the resulting code. Example:

const contextify = require("node-module-context");

const execute = contextify("path/to/your/file", {
  preCompiler (source) {
    return transform(source);
  }
});

execute(context);

TODO

  • [x] Split code for testability.
  • [ ] Write unit tests.
  • [ ] Add option to allow choosing which modules to be resolved by global require and which by the contextified require method for performance reasons.
  • [x] Preload user modules.
  • [ ] Preload npm packages.