Published on

Why You Should Use the NPKill Node Module

Last Modified on
Last modified on
Authors
Why You Should Use the NPKill Node Module
Photo by Andre Hunter on Unsplash

Recently I was introduced to the npkill node module on Twitter by T. Eric Cabrel:

what a great idea and tool it is! I have so many projects on my laptop that use npm. And do you know how much disk space they were taking up? 34GB. 34GB! That is a MEGALOAD of disk space!

As long as you have Node.js and npm installed, it is very easy to use. I decided to remove 10GB for starters. This is what I had to do:

First, I had to install the package. I did not actually permanently install it, because I did not want to install it globally, but just temporarily download it. That is because I was not attaching it to any specific project or folder. That then meant using the npx command prefix.

What is npx?

According to npmjs.org,

(The npx command prefix) ...allows you to run an arbitrary command from an npm package (either one installed locally, or fetched remotely) in a similar context as running it via npm run.

What this really means is that if you want to use the latest version of a package without installing it globally (which is permanent until you choose to delete it manually), you can use npx before the command you want to execute.

I ran the npx npkill -d development command in order to temporarily install npkill and use it in my development directory. The first time I ran the command, I was prompted as to whether I wanted to install it or not. I responded by pressing the y key for yes. After that, I was no longer prompted. npx automatically re-installed the package without asking.

After npkill is installed something like the following should appear in your Terminal window:

npkill output to Terminal screenshot 1

The "space saved" should initially show "0", because no space is"initially saved". As indicated in the screenshot, I already have deleted two instances of node_modules when I took this screenshot.

The process is very easy, and tells you what to do. The instructions are highlighted in yellow. The following is what my Terminal window instance looked like after I deleted 2.86GB worth of node_modules:

npkill output to Terminal screenshot 2

And that is it!

To learn more about the npkill Node module, visit NPKILL on the NPM registry.