Quickly remove all node_modules folders from your system to free up disk space

Because you can always create a node_modules folder anytime from package.json

Whenever, we are working with React, Angular, Nodejs or any other library or framework, we always need to create a node_modules folder which takes up a lot of space and we don't bother to remove the node_modules folder once our job is done.
So we end up creating many node_modules folders in various project folders which takes up a lot of hard-disk space on our filesystem.

Today we will see a very helpful command npkill which scans our file system and easily allows us to remove the node_modules folders in a single click within seconds.

Installation

You actually, don't need to install the package to use it.

You just need to run it as

npx npkill

*npx*_ allows to run npm commands without installing the package._

You can, however, install the npkill package if you really need to install it using

npm install npkill -g

and then you can just run npkill from any directory to delete the node_modules folder.

Once the list is displayed, you can navigate using arrow keys and delete the specific node_modules directory by hitting the spacebar.

To exit out of the list, press q key on your keyboard or Control + C

By default, npkill will list out the node_modules folders from the current directory and its subdirectories.

So if you want to delete all the node_modules from your system, you need to execute the npkill command from your home or root directory.

Speed

You might think that it will take a lot of time to delete a single node_modules folder using npkill, but that's not true. Actually, it's very fast. within some seconds, the folder will be deleted. So Just give it a try.

Enjoyed this article?

Share it with your network to help others discover it

Continue Learning

Discover more articles on similar topics