Cover image for npkill - The solution to deleting node_modules easily, with style

npkill - The solution to deleting node_modules easily, with style

carlillo profile image Carlos Caballero Updated on ・3 min read


One of my happiest memories related to software development was when I developed and distributed my first project among my friends and family. Although I learned to develop long before then, it was in 2003 when I developed the classic game Arkanoid in assembler. Of course, this game couldn't be distributed online, since we had no internet at home, GitHub didn't exist, and, in my particular case, I didn't know any social networks for developers. Today, this story is a beautiful memory stored in my mind... And possibly in old floppies, kept in old boxes somewhere in my parent's house.

Nowadays, I teach developers and I'm constantly encouraging my students to give visibility to all their projects, and to rely on the community, since it is there where they will find the best colleagues, outside the classroom. The story I previously told would have gone very differently if it had happened today, since the first thing I would have done is to publish my project on all social networks, and find a good mentor to learn from her/him.

Although you can't go back in time, I am pleased to present a project developed by two of my former vocational training students, which is published on GitHub. I think it is a great contribution to the community.

This tool solves a traditional problem that us node.js developers have when we install a large set of dependencies in our projects. The number of node_modules folders in our computer grows as we develop more projects.
More often than not, we don't remember where the node_modules folders are stored, so it is very difficult to find and delete them.


These two students (now developers) have developed an npm package which allows management of our old and heavy node_modules folders. Therefore, I'm very happy to announce npkill.



This tool allows you to list any node_modules directories in your system, as well as the space they take up. You can then select which ones you want to erase to free up space. Yay!

Before to explain the easiest steps to get this essential tool, I'm going to show a GIF in which I've been using this tool in my laptop to save more than 1 GiB over a work folder.



$ npm i -g npkill



By default, npkill will scan for node_modules starting at the path where npkill command is executed.

Move between the listed folders with , and use Del to delete the selected folder.

To exit, Ctrl + c.


options |

Warning: In future versions some commands may change


  • Search node_modules directories in your projects directory:
npkill -d ~/projects

# other alternative:
cd ~/projects
  • Automatically delete all node_modules that have sneaked into your backups:
npkill -d ~/backups/ --delete-all


In this post, I've shown you two important topics:

  1. This amazing tool which will be very helpful to manage our node_modules.
  2. You are also able to develop an awesome project. A few months ago they were in class discovering fundamental concepts like "promises", "hoisting", "design patterns" or "tooling". Therefore, remember that you are able to do anything too.

My recommendation is to visit the npkill official repo, read the code and start helping them in this fun adventure of creating open-source content.

More, More and More...

Originally published at https://carloscaballero.io.

Posted on by:

carlillo profile

Carlos Caballero


I'm PhD. in Computer Science from Málaga, Spain. Currently, I am teaching developers and degree/master computer science how to be experts in web technologies and computer science.


Editor guide

Awesome! Great work guys!

Unfortunately the option --delete--all doesn't work, at least for me. I tried different shells (fish shell, zsh and bash) plus iTerm 2 and the default Terminal on macOS (10.14.6). But the individual select worked like a charm!


Just published a patch. --delete-all should be fixed and working properly. If you encounter any more issues, don't hesitate to let me know and I will do my best to fix them. Thank you for your comment and your patience :D


wow! That was fast! I even forked the project to take a look if I could help but I didn't take a look on it yet.
It working as expected now! 👍🏻


Oh no... will have to work on it. Thanks for letting us know 😊



The guys are working in improve the project. They are very happy cause that the tool is useful to the community (in my Linux works perfectly 😂)


Just a simple question: wouldn't a basic find/rm bash command work just fine, without the need of an extra globally installed tool?

Or does this tool add a serious feature?


As you probably know already, using find/exec will delete every single result the command yields.
Npkill allows you to select which folders you want to erase, as well as calculating the amount of freed space... Without having to remember any lengthy commands :D


On Mac just:

find . -name "node_modules" -exec rm -rf '{}' +'

would do the same I think.


Except for folder selection, on basically every unix-enabled system (including windows through WSL, or cygwin).

But this one also removes files that may be called node_modules.

A better one would be to have find . -type d -name node_modules -exec rm -rf {} +.


used just now but didn't delet anything


Hi taskhyn!

We believe it may be related to directory permissions. We will release a patch shortly that will notify the user about any errors related to permission problems.

Sorry for the inconvenience and thanks for trying npkill.


Hi @sarbazx !

What were your steps to run the tool?



started by invoking command and then according to instruction pressed delete button or is it different key on mac?

Hi @sarbazx ! I am having trouble with the same. Did you managed to figure it out?

Hi, no i was just testing it.

Hey guys!

Just figured out I made a stupid mistake. Apparently the del keycode is different in mac, which is why it doesn't work (key is undefined). Will fix it right now!! So sorry!!

Hey @Nya!

Quiet and sure the patch is on its way :-).

Thank you very much for your app.

My MacBook wants to reduce the weight of the node_modules.

Cheer up!



It's not good practice to install NPM packages with sudo, I'd rather use npx command.
Of course correct me if I'm wrong.
But good job for developers it's a package I'll use definitely.


Astonishing.. I'd say just one word...


Hi @th3n00brc0d3r!

They are very happy for their first open source project.



Awesome Jobs Guy!!!


Love the illustration, btw. ;)


Hi @codemouse92 ,

The logo has been created by them too.



Thanks a lot, Mate :)


AWESOME tool!! Didn't realized I wasted over 10G of space on node_modules!

Feature suggestion: Row highlighting or something like that.


Glad you found it useful! Great suggestion, will add it to the roadmap, thanks ;D


This is really awesome, I still remember when I used to manually delete each node modules folder one by one. Great addition to the npm community indeed.


Well this helps a ton of things. Great share


Hi @webdevinci !

How many tons of gigabytes have you freed up?😂😂



I have 6.2 GB there (not too bad, not too good). I figure i can get rid of a 1/3 at least! It's a beautiful thing


Really nice!



Cool idea! Thank you ❤️