NPM.NodeModules (NPM v0.6.0)

Copy Markdown View Source

Inspect and query the node_modules directory.

Provides functions to enumerate installed packages, compare against the lockfile, and detect anomalies.

Summary

Functions

Compare installed packages against the lockfile.

Get the total disk size of node_modules in bytes.

Count the total number of files in node_modules.

List all installed packages in node_modules.

Get the installed version of a package by reading its package.json.

Functions

diff(lockfile, dir \\ "node_modules")

@spec diff(%{required(String.t()) => term()}, String.t()) ::
  {[String.t()], [String.t()]}

Compare installed packages against the lockfile.

Returns {missing, extra} where:

  • missing — packages in lockfile but not in node_modules
  • extra — packages in node_modules but not in lockfile

disk_size(dir \\ "node_modules")

@spec disk_size(String.t()) :: non_neg_integer()

Get the total disk size of node_modules in bytes.

file_count(dir \\ "node_modules")

@spec file_count(String.t()) :: non_neg_integer()

Count the total number of files in node_modules.

installed(dir \\ "node_modules")

@spec installed(String.t()) :: [String.t()]

List all installed packages in node_modules.

Returns a sorted list of package names (including scoped).

version(name, dir \\ "node_modules")

@spec version(String.t(), String.t()) :: String.t() | nil

Get the installed version of a package by reading its package.json.