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







