How To NPM Unistall Unused Packages in Node - Js - by VithalReddy - stackFAME - Medium
How To NPM Unistall Unused Packages in Node - Js - by VithalReddy - stackFAME - Medium
Published in stackFAME
VithalReddy Follow
Save
Consider, you’re developing a shiny new node.js project and according to your need,
design, and business logic, you’ve installed many NPM packages, but at the end you
realized, that you don’t need many packages, so now you want to remove all unused
npm packages and sub-modules of it, which is not defined in package.json, for that
purpose npm cli, provides a method, which we will discuss and learn how to use it
in this node.js how to tutorial, so let’s learn npm command to uninstall unused
packages in Node.js.
This npm command can be used to remove not required packages from your
node_modules directory and devDependencies modules if NODE_ENV
environment variable is set to production and if you don’t want remove
devDependencies then you need to set — production=false
https://medium.com/stackfame/how-to-npm-unistall-unused-packages-in-node-js-ea80afb6d1a7 1/2
5/1/23, 10:48 How to NPM unistall unused packages in Node.js | by VithalReddy | stackFAME | Medium
2. To remove any specific node package run the command npm prune <pkg>
3. run the npm prune command to remove unused or not required node packages
from Node.js
5. if you don’t want to unbuild devDependencies then you need to set –production
flag false npm prune — production=false
If you see an npm module remain in your node_modules directory even after
running npm prune even though it’s not in package.json, then you need to check
your npm-shrinkwrap.json if it’s present then you need to delete it and then You can
follow below method to solve this problem.
If you want to completely remove the node_modules directory and want to do a fresh
Open in app Get unlimited access
npm installthen this below one-line can be very useful:
But, This can take some time depending upon the size of the node_modules
directory.
If you have any queries, please comment below and thanks for reading this how-to
guide.
298
https://medium.com/stackfame/how-to-npm-unistall-unused-packages-in-node-js-ea80afb6d1a7 2/2