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-analyzer

v0.5.0

Published

Determine dependencies for a given node.js file, directory tree, or module in code or on the command line

Readme

require-analyzer

Determine dependencies for a given node.js file, directory tree, or module in code or on the command line

Status

Build Status

Installation

Installing npm (node package manager)

Installing require-analyzer

NOTE: If you're using npm >= 1.0 then you need to add the -g parameter to install require-analyzer globally.

Usage

There are two distinct ways to use the require-analyzer library: from the command line or through code. The command line tool is designed to work with package.json files so make sure that you have created one for your project first. Checkout jitsu for a quick and easy way to create a package.json.

For more information read our blog post at blog.nodejitsu.com.

Command-line usage

Using require-analyzer from the command line is easy. The binary will attempt to read the package.json file in the current directory, then analyze the dependencies and cross reference the result.

Here's a sample of require-analyzer analyzing it's own dependencies:

Programmatic usage

The easiest way to use require-analyzer programmatically is through the .analyze() method. This method will use fs.stat() on the path supplied and attempt one of three options:

  1. If it is a directory that has a package.json, analyze require statements from package.main
  2. If it is a directory with no package.json analyze every .js or .coffee file in the directory tree
  3. If it is a file, then analyze require statements from that individual file.

Lets dive into a quick sample usage:

  var analyzer = require('require-analyzer');
  
  var options = {
    target: 'path/to/your/dependency' // e.g /Users/some-user/your-package
    reduce: true
  };
  
  var deps = analyzer.analyze(options, function (err, pkgs) {
    //
    // Log all packages that were discovered
    //
    console.dir(pkgs);
  });
  
  //
  // The call the `.analyze()` returns an `EventEmitter` which outputs
  // data at various stages of the analysis operation.
  //
  deps.on('dependencies', function (raw) {
    //
    // Log the raw list of dependencies (no versions)
    //
    console.dir(raw);
  });
  
  deps.on('search', function (pkgs) {
    //
    // Log the results from the npm search operation with the current
    // active version for each dependency
    //
    console.dir(pkgs);
  });
  
  deps.on('reduce', function (reduced) {
    //
    // Logs the dependencies after they have been cross-referenced with 
    // sibling dependencies. (i.e. if 'foo' requires 'bar', 'bar' will be removed).
    //
    console.dir(reduced);
  });

Further analyzing dependencies

Sometimes when dealing with dependencies it is necessary to further analyze the dependencies that are returned. require-analyzer has a convenience method for doing just this:

  var analyzer = require('require-analyzer');
  
  var current = {
    'foo': '>= 0.1.0'
  };
  
  var updated = {
    'foo': '>= 0.2.0',
    'bar': '>= 0.1.0'
  };
  
  var updates = analyzer.updates(current, updated);
  
  //
  // This will return an object literal with the differential
  // updates between the two sets of dependencies:
  //
  // {
  //   added: { 'bar': '>= 0.1.0' },
  //   updated: { 'foo': '>= 0.2.0' }
  // }
  //

Tests

Author: Charlie Robbins