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

search-requires

v2.2.1

Published

Find require() calls to a module

Readme

search-requires

Find require() calls to a given module

Command Line Usage

SYNOPSIS
      search-requires [OPTIONS] [INPUT...]

DESCRIPTION
      search-requires searches the named INPUT paths for require() calls
      to modules specified with the -m option. If an input path is not
      given, the current working directory is used.

      When a require() call is encountered, the required module will
      also be searched if it is a path to a local file module.

OPTIONS

      -m MODULE, --module MODULE
            Search for require() calls to MODULE.

EXAMPLES
      search-requires -m fs -m events
          Search the current directory for require() calls to the "fs"
          and "events" modules.

      search-requires -m lib/fs-util.js $(find . -name *.js)
          Search all js files for require() calls to the local
          lib/fs-utils.js file.

See which node core modules use the stream module:

$ search-requires -m stream /src/node/lib/*.js
/src/node/lib/crypto.js
/src/node/lib/fs.js
/src/node/lib/_http_incoming.js
/src/node/lib/_http_outgoing.js
/src/node/lib/net.js
/src/node/lib/repl.js
/src/node/lib/_stream_readable.js
/src/node/lib/_stream_writable.js
/src/node/lib/_tls_legacy.js

API Usage

var find = require("search-requires");
var finder = find("some-module", "./a.js");
finder.on("data", function(obj) {
  // Module at `obj.path` requires "some-module"
  console.log(obj.path);
});

API

var search = require("search-requires");

search(modules, input)

Return a stream object and start searching paths for require calls to modules, emitting a data object for each matching call found.

modules should be a target search module or an array of modules. Local file modules (e.g., starts with "./") will be resolved from the current working directory, otherwise the module will be treated from a named module resolved from node_modules.

input should be a path or an array of paths to use as entry points for the search. If a path to a directory is used, it will be resolved to a path using require.resolve semantics using the current working directory.

The stream's data objects will have the following properties:

  • path: Path to the file with matching require() call
  • module: Name of the required module

An error event will be fired if an error occurs while searching files.

An end event will be fired once all files have been searched.

Errors

If a local file module being required is not able to be resolved, error.code will be "MODULE_NOT_FOUND".

If there is an error parsing a module, error.code will be "SYNTAX_ERROR".

Installation

npm install search-requires