npm prune: Remove Extraneous Packages
npm prune removes installed packages that are no longer declared.
In a Docker build you often install everything to test, then prune dev dependencies before copying node_modules into the runtime image.
Common flags
--omit=dev- drop devDependencies--dry-run- preview removals--json- structured output
Example in CI
Slim a production image after building.
shell
npm prune --omit=devIn CI
Common in multi-stage Docker builds to shrink the final image. Equivalent to a fresh npm ci --omit=dev in many pipelines.
Key takeaways
--omit=devstrips dev packages.- Useful before copying node_modules to runtime.
- Preview with
--dry-run.