Node Modules Inspector

1.4.2 · active · verified Tue Apr 21

Node Modules Inspector is an interactive command-line interface (CLI) and web UI tool designed for comprehensive analysis and visualization of the `node_modules` directory within JavaScript/TypeScript projects. Maintained by Anthony Fu, the package is currently at version 1.4.2 and receives regular updates, as indicated by its recent feature and bugfix releases. It helps developers understand their project's dependency graph, identify installed dependencies, analyze package sizes, detect module types (ESM vs. CJS), and locate duplicates or version conflicts. The tool differentiates itself by offering an interactive UI that can be launched locally or built into a static report for hosting, supporting various package managers including npm, pnpm, and Bun. It is particularly useful for debugging dependency issues, optimizing bundle sizes in large projects or monorepos, and quickly assessing potential vulnerabilities through its report view.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically analyze a project's `node_modules` directory and log summary information.

import { analyzeProject } from 'node-modules-inspector/core';
import path from 'node:path';
import process from 'node:process';

async function inspectCurrentProject() {
  const projectPath = process.cwd();
  console.log(`Analyzing node_modules in: ${projectPath}\n`);

  try {
    // The `analyzeProject` function (inferred) would perform the core logic.
    // In a real scenario, this might return a structured report object.
    const report = await analyzeProject(projectPath, {
      // Optional: Specify package manager if not auto-detected
      packageManager: 'npm',
      // Optional: Include dev dependencies in the analysis
      includeDevDependencies: true,
      // Optional: Filter modules based on criteria
      filter: (module) => !module.name.startsWith('@types/'),
    });

    console.log('Analysis Complete! Key Insights:');
    console.log(`Total unique packages: ${report.packages.length}`);
    console.log(`Total disk size: ${report.totalSizeHumanReadable}`);
    console.log(`Duplicate packages found: ${report.duplicates.length}`);
    console.log(`Modules with known vulnerabilities: ${report.vulnerabilities?.length || 0}`);
    console.log('\nTo view the full interactive report, run:');
    console.log('npx node-modules-inspector');

  } catch (error) {
    console.error(`Error during analysis: ${error.message}`);
    console.error('Ensure you run this in a project with a node_modules directory.');
    console.error('If this error persists, try running `npx node-modules-inspector` directly.');
  }
}

inspectCurrentProject();

view raw JSON →