Node modules are famous for being the heaviest object in the universe 😂 and deleting them is no joke. It takes a long of time and we even end up with freezed and unresponsive screens, but not anymore.
There is an npm package that could help us to delete node modules faster and without any hassle.
npkill comes to the rescue!
You don't need to install npkill , just run npx npkill in your terminal
It will then scan for node_modules starting at the path where npkill command is executed and list them.
Move between the listed node modules folders with arrow keys, and press Space to delete it.
Simple, isn't it?
Hope you liked the post and learned a trick along the way! 😃
✋ Hey! Before you go 🏃
If you enjoyed this trick, You can also follow me on
LinkedIN | Dev.to | Github | Twitter
Stay tuned for more such tricks ✨
Oldest comments (26)
Been using NPKill for a while - definitely recommend
nice tool, but have you tried rimraf. It can delete any folder recusively with a simple command i.e
npx rimraf folder_name
. And it also provieds api to work in node projects.rm -rf node-modules
does the job toonpx npkill
can recursively traverse your directoriesSo you can use it from e.g. your HOME folder and then remove every unnecessary node_modules in every directory/project
So can rm -rf **/node_modules
This will remove everything without any control
With npkill you can select each
node_modules
individuallyTry it and you will see what I mean
No it does not :-). It is
rm -rf node_modules
doesI use rm - rf... for years and find is super fast ... Never knew about npkill will check it out
@yaman27 you should add a gif to this blog article :)
That could make it a bit more clear why this is so powerfull
Will surely do from next time. Thanks!
I'm also very curious about in what os does recursive deletion takes long time. I'm in Ubuntu and macOS for most of the time, rm -rf takes no time to remove the whole node_modules directory.
So the solution for excessive node_modules is to install another npm package?
It shouldn't be that hard.
You don't need to install another NPM package to remove node_modules you can use this command in your terminal and it will do exactly that
find . -name "node_modules" -type d -prune -print -exec rm -rf '{}' \;
this will look inside the folder you currently are in to remove all node modules folders that are found in the current directory and subdirectories recursively.
i am getting Acess denied, even though i am trying on admin CMD
This command is for mac and linux I don't think it will work in Windows CMD ... but if should work for you if you install cmder terminal which is a console emulator for windows ... you can get it here cmder.net/
Credits to Fireship?
Credits to codevolution. But Fireship is a great channel too.
Why not Just mv node_modules fucking_modules && npm install && rm -rf fucking_modules
What's wrong with
rm -rf node_modules
?i learned to love pnpm as alt to npm and yarn to have a central repository of all node=modules
Right mouse and choose delete :D
I haven't found myself in a situation where I need to delete node modules in different project all at once. rm still works fine for me.