liveBook · Manning

Npm

As explained in Fast by Default

npm is a package manager and registry ecosystem for installing, resolving, and managing JavaScript packages.

npm manages JavaScript packages and their dependency tree. For Node.js services, dependencies remain in node_modules, so deployment size requires measuring the directory rather than inspecting a bundled artifact. section 8.2.2

Use npm to investigate and reduce dependency size:

  • Run npm ls --all to inspect the complete dependency tree and identify duplicated versions. section 8.2.2
  • Run npm dedupe to flatten compatible nested dependencies and reclaim space. section 8.2.2
  • Use npm ci --omit=dev for production deployments so development dependencies are excluded. section 8.2.2

Finding oversized packages

Measure node_modules, sort package directories by size, then inspect unusually large packages. Check a candidate before adoption with npx npm-size package-name and audit the installed tree with npx cost-of-modules; replace a package when a lighter alternative exists. section 8.2.2

npm ls --all

Inspect the complete npm dependency tree to expose duplicate versions and unexpected transitive dependencies. section 8.2.2

How Fast by Default covers it

How deep it goes
Traces dependency trees, measures installed packages, deduplicates versions, and excludes development dependencies, without covering package publishing.
Examples
Uses npm ls --all, npm dedupe, npm ci --omit=dev, npm-size, cost-of-modules, and node_modules size listings.
What it assumes
Assumes familiarity with Node.js services, npm dependencies, and production deployments.
What you can do after
Diagnose/debug with it by locating duplicate, oversized, or unnecessary dependencies before production deployment.
How it connects
Connects Node.js, JavaScript packages, dependency trees, transitive dependencies, and production deployments.

Also explained in

Compare how 8 books explain npm →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fast by Default. The section links point to the parts of the book it draws on.