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

require-load

v2.2.0

Published

Asynchronously require files in node js.

Readme

An asynchronous module loader for nodejs that integrates with the existing module system.

Installation

Npm

npm install require-load

API

load(file: String, options: Object) -> {Promise}

Asynchronously require a specific file. File name resolution works exactly the same as the native require function.

import load from 'require-load'

load('./example.js').then(result => {
  // Result will be the exports of `example.js`, subsequent calls will be cached.
  // You can even get the cached version using plain old require.
  require('./example.js') === result
}).catch(err => {
  // Handle file load error.
})

load.resolve(file: String, options: Object) -> {Promise}

Asynchronously resolve a file path. (Like require.resolve but async.).

import { resolve } from 'require-load'

resolve('./example.js').then(fullpath => {
  // Result will be the full path of './example.js'
}).catch(err => {
  // Handle file resolve error.
})

Options (same for both load and load.resolve)

cache=false (default true)

When the cache option is false the module will be re-evaluated and not cached for the next load call.

load('./example.js', { cache: false }).then(result1 => {
  load('./example.js', { cache: false }).then(result2 => {
    result1 !== result2 // Module was not cached.
  })
})

directory=__dirname (default relative to the function calling load)

You can optionally choose which directory the resolve files from. By default this will be relative to where ever this module is required.

load('./main.test.js', { directory: __dirname + '/test' }).then(result => {
  // Will resolve modules from the test folder instead of where this was required.
})

file=__filename (default relative to the function calling load)

You can also optionally specify a file from which the loader should run. (This also defaults the directory option to be the dirname of the file).

load('./main.test.js', { file: __dirname + '/test/custom.test.js' }).then(result => {
  // Will resolve modules relative to the custom.test.js file instead of where this was required.
})

resolve.fileSystem=MemoryFileSystem (default to nodeFileSystem.)

You can choose the file system to use when resolving and compiling files. The default will just be the standard 'fs' module but you can also get fancy and use other files systems like 'memory-fs'.

import path from 'path'
import MemoryFileSystem from 'memory-fs'
const memoryFs = new MemoryFileSystem()

// Save a file to memory fs.
memoryFs.writeFileSync(path.join(__dirname, './main.test.js'), 'module.exports = "hello world"')

// Load the file from memory.
load('./main.test.js', { resolve: { fileSystem: memoryFs } }).then(result => {
  result === 'hello world'
})

Clearing the cache

Clearing a file from the cache is the exact same as any other node module (once the file has loaded).

  load('./example.js').then(result => {
    // Remove from the require cache manually.
    delete require.cache[require.resolve('./example.js')]
  })

Custom extensions

Just like node's require you can add or overwrite the file extensions, however instead of calling the extension function with a filename it will be called with the file's contents.

// A naive babel loader for babel es6 files.
import babel from 'babel-core'
load.extensions['.es6'] = function parseCustomFile (module, script) {
  module._compile(babel.transform(script), module.filename)
}

Contributions

  • Use npm test to run tests.

Please feel free to create a PR!