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

lazy_require

v0.0.1

Published

Like require, but the library is only actually loaded when it's used.

Readme

lazy_require

npm tests

Like require, but the library is only actually loaded when it's used.

Note: This project is in early development, and versioning is a little different. Read this for more details.

Why should you care?

With node's standard require function, as soon as it is run, it loads the linked module along with anything else it requires etc. down the tree. For larger dependencies, this can take a while -- I've seen larger libraries soak up 500ms+ of load time off a require call.

At the same time, in 99% of cases, you do not actually need a required module to be executed immediately, you only need it to be executed when it's used. But since the convention in node is to load all dependencies at the top of each file, you are always taking on the entire dependency load upfront no matter when, whether you actually end up making a call to that module that uses all of its dependencies. For example, let's look at a basic example module, which serves as an API for interacting with doges:

var DogeCreator = require('foo'),
    DogePetter = require('bar');

module.exports = {
  createDoge: function(name){ return new DogeCreator(name) },
  petDoge: function(){ DogePetter.pet(); return true }
}

Now, let's look at another file that requires and uses this module:

var dogeAPI = require('dogeAPI');

dogeAPI.createDoge('fluffy');

In this example, although we only used the DogeCreator library, we fully loaded both DogeCreator and DogePetter. So if DogePetter was a heavy library, you are simply wasting the time it takes to load that dependency.

What lazy_require does is solves this exact issue. You can lazy_require a module, but the module will only actually be loaded once you use it. So if we used lazy_require in the example above rather than require, we would not load DogePetter at all, saving any time it took to load that entire module (and its dependency tree).

Installation

npm install lazy_require

Usage

Lazy require is a hacky hack, but it works, and is, as far as I know, entirely safe. But because it's a hack, it's not quite as smooth as the built in require in some ways. By default, it will assign the library name you pass it to a variable of the same name. For example:

lazy_require('fs');
console.log(fs); // it's defined!

However, if you want to assign it to a specific name, you need to pass that as the second parameter. For example:

lazy_require('../lib/doge_api', 'doge')
console.log(doge); // it works!

Do not try to use the output of lazy_require like you would with a normal require -- the assignment has to happen through the second parameter. That's all!

License & Contributing