Delete unused node_modules in a second and enjoy some free space!

Published on : August 08,2022
Delete unused node_modules in a second and enjoy some free space!

Hi dev.

In this article I'll tell you about a cool tool I just found on npm, called npkill, that helps you cleaning node_modules from projects you no longer user but still want to keep.

 

Table of Contents

  • The problem
  • The solution
  • Installation
  • Options
  • Conclusions

 

The problem

This tool is mostly for active developers who have many projects in their computer, but everyone can get benefit from it.

Everytime you run npm install or yarn on a new repository, you're basically throwing a lot of files inside the local node_modules folder.

As time goes by, you'll end by having a lot of those folders on old and dusty projects sitting there, wasting space in your disk.

For many reasons, you might want to keep those projects and not delete them, for example because of some particular implementations you want to keep as examples or template, and that's totally fine, but you don't need the node_modules folder!

 

The solution

I found a cool tool that helps exactly for this scenario, it's called npkill and you can find it on npm.js.

npkill

 

This CLI tool will navigate for your disk looking for node_modules folders and will list all of them. After the scan, you will have the power to select them one by one and hit SPACE to delete the entire folder.

 

Installation

As it's a regular package on npm, it's as easy as

npm i -g npkill

Once you've installed in globally, you can run

npx npkill

and the hunt begins!

 

Options

The tool comes with some options you can find in the README on GitHub, but I'd like to put the spotlight in some of them that are quite useful

  • --sort or -s => Allows to sort by size or path. I think sorting by size is super handy!
  • --target or -t => Allows to set a different target folder than node_modules. You can use this option to clean up dist or build folders for example.
  • --directory or -d => Allows to specify the folder to look at. By default is the current path, but you can run it from everywhere and set a different path without repositioning your terminal.
     

 

Conclusions

And that was it! I found this really handy tool by browsing the internet and cleaned up approximately 8GB on my computer, I was so happy that I wanted to share it with you!

 

Hope it will help you!

Categories : React

Tags : React Js

Praful Sangani
Praful Sangani
I'm a passionate full-stack developer with expertise in PHP, Laravel, Angular, React Js, Vue, Node, Javascript, JQuery, Codeigniter, and Bootstrap. I enjoy sharing my knowledge by writing tutorials and providing tips to others in the industry. I prioritize consistency and hard work, and I always aim to improve my skills to keep up with the latest advancements. As the owner of Open Code Solution, I'm committed to providing high-quality services to help clients achieve their business goals.


0 Comments

Leave a comment

We'll never share your email with anyone else. Required fields are marked *

Related Articles

Create Basic Login form with React JS Example
Praful Sangani By Praful Sangani - July 22,2022
React Hooks: Array Destructuring Fundamentals
Praful Sangani By Praful Sangani - July 25,2022
Groups in React Textbox
Praful Sangani By Praful Sangani - August 03,2022