0% found this document useful (0 votes)
180 views2 pages

How To NPM Unistall Unused Packages in Node - Js - by VithalReddy - stackFAME - Medium

This document discusses how to uninstall unused npm packages in Node.js projects. It explains that the npm prune command can be used to remove packages that are not defined in the package.json file. The steps are to first remove unused packages from package.json, then run npm prune to remove those packages from node_modules. Additional options like --production can control whether devDependencies are also removed. Running rm -rf node_modules && npm install will completely remove and reinstall all packages.

Uploaded by

cartena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
180 views2 pages

How To NPM Unistall Unused Packages in Node - Js - by VithalReddy - stackFAME - Medium

This document discusses how to uninstall unused npm packages in Node.js projects. It explains that the npm prune command can be used to remove packages that are not defined in the package.json file. The steps are to first remove unused packages from package.json, then run npm prune to remove those packages from node_modules. Additional options like --production can control whether devDependencies are also removed. Running rm -rf node_modules && npm install will completely remove and reinstall all packages.

Uploaded by

cartena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

5/1/23, 10:48 How to NPM unistall unused packages in Node.

js | by VithalReddy | stackFAME | Medium

Published in stackFAME

VithalReddy Follow

Oct 1, 2017 · 2 min read · Listen

Save

How to NPM unistall unused packages in Node.js

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.

What is npm prune and how to use it?


1. npm prune <pkg> — production

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

Now let’s see, how to use npm prune with example:

How to use npm prune with an example?


steps by step procedure to use npm prune:

Steps to Remove unused packages from Node.js


1. First, remove the npm packages from packages.json file and save the file.

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

4. if you want to remove devDependencies then run prune command with –


production flag npm prune — production=true

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.

READ Get List of all files in a directory in Node.js

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:

1. rm -rf node_modules && npm install

That was quick!

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.

first appeared on StackFAME.

Java Script Nodejs NPM

298

https://medium.com/stackfame/how-to-npm-unistall-unused-packages-in-node-js-ea80afb6d1a7 2/2

You might also like