Introduction
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.
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.
Installation
$ npm i -g npkill
Usage
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
Examples
- Search node_modules directories in your projects directory:
npkill -d ~/projects
# other alternative:
cd ~/projects
npkill
- Automatically delete all node_modules that have sneaked into your backups:
npkill -d ~/backups/ --delete-all
Conclusions
In this post, I've shown you two important topics:
- This amazing tool which will be very helpful to manage our node_modules.
- 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.
Top comments (31)
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
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?
Thanks!
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!
Thanks!
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
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.
Totally true!
Astonishing.. I'd say just one word...
Hi @th3n00brc0d3r!
They are very happy for their first open source project.
Thanks.
Thanks a lot, Mate :)
Well this helps a ton of things. Great share
Hi @webdevinci !
How many tons of gigabytes have you freed up?😂😂
Thanks!
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
Hi!
Really nice!
☺️
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.
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
On Mac just:
find . -name "node_modules" -exec rm -rf '{}' +'
would do the same I think.