Removing extraneous NPM packages

Synopsis

npm prune [[<@scope>/]<pkg>…] [–production] [–dry-run] [–json]

Description

This command removes “extraneous” packages. If a package name is provided, then only packages matching one of the suppli…



Synopsis

npm prune [[<@scope>/]<pkg>...] [--production] [--dry-run] [--json]



Description

This command removes “extraneous” packages. If a package name is provided, then only packages matching one of the supplied names are removed.

Extraneous packages are those present in the node_modules folder that are not listed as any package’s dependency list.

If the --production flag is specified or the NODE_ENV environment variable is set to production, this command will remove the packages specified in your devDependencies. Setting --no-production will negate NODE_ENV being set to production.

If the --dry-run flag is used then no changes will actually be made.

If the --json flag is used, then the changes npm prune made (or would have made with --dry-run) are printed as a JSON object.

In normal operation, extraneous modules are pruned automatically, so you’ll only need this command with the --production flag. However, in the real world, operation is not always “normal”. When crashes or mistakes happen, this command can help clean up any resulting garbage.



Summary

To remove extraneous packages (packages that are installed but not in dependency list) run the following command:

npm prune

To remove all dev packages add --production flag:

npm prune --production

Buy Me A Coffee

With all that being said, I highly recommend you keep learning!

Thank you for reading this article. Please feel free to connect with me on LinkedIn and Twitter.


Print Share Comment Cite Upload Translate
APA
Rajesh Kumar Yadav | Sciencx (2024-03-29T15:38:16+00:00) » Removing extraneous NPM packages. Retrieved from https://www.scien.cx/2021/05/09/removing-extraneous-npm-packages/.
MLA
" » Removing extraneous NPM packages." Rajesh Kumar Yadav | Sciencx - Sunday May 9, 2021, https://www.scien.cx/2021/05/09/removing-extraneous-npm-packages/
HARVARD
Rajesh Kumar Yadav | Sciencx Sunday May 9, 2021 » Removing extraneous NPM packages., viewed 2024-03-29T15:38:16+00:00,<https://www.scien.cx/2021/05/09/removing-extraneous-npm-packages/>
VANCOUVER
Rajesh Kumar Yadav | Sciencx - » Removing extraneous NPM packages. [Internet]. [Accessed 2024-03-29T15:38:16+00:00]. Available from: https://www.scien.cx/2021/05/09/removing-extraneous-npm-packages/
CHICAGO
" » Removing extraneous NPM packages." Rajesh Kumar Yadav | Sciencx - Accessed 2024-03-29T15:38:16+00:00. https://www.scien.cx/2021/05/09/removing-extraneous-npm-packages/
IEEE
" » Removing extraneous NPM packages." Rajesh Kumar Yadav | Sciencx [Online]. Available: https://www.scien.cx/2021/05/09/removing-extraneous-npm-packages/. [Accessed: 2024-03-29T15:38:16+00:00]
rf:citation
» Removing extraneous NPM packages | Rajesh Kumar Yadav | Sciencx | https://www.scien.cx/2021/05/09/removing-extraneous-npm-packages/ | 2024-03-29T15:38:16+00:00
https://github.com/addpipe/simple-recorderjs-demo