DEV Community

loading...
Cover image for Delete Node Modules like a PRO 😎

Delete Node Modules like a PRO 😎

Yaman Sharma
A developing Developer
・1 min read

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.

node-modules joke

There is an npm package that could help us to delete node modules faster and without any hassle.

npkill comes to the rescue!
npkill logo

You don't need to install npkill , just run npx npkill in your terminal

npx npkill

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.

Select nodemodules and delete

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 ✨

Discussion (23)

Collapse
manjit2003 profile image
Manjit Pardeshi

rm -rf node-modules does the job too

Collapse
benjaminv profile image
benjaminv

No it does not :-). It is rm -rf node_modules does

Collapse
shinigami92 profile image
Shinigami

npx npkill can recursively traverse your directories
So you can use it from e.g. your HOME folder and then remove every unnecessary node_modules in every directory/project

Collapse
mpetuska profile image
Martynas Petuška

So can rm -rf **/node_modules

Thread Thread
shinigami92 profile image
Shinigami

This will remove everything without any control

With npkill you can select each node_modules individually

Try it and you will see what I mean

Collapse
zakiazfar profile image
Mohd Ahmad

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.

Collapse
neenus profile image
Neenus Gabriel • Edited

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.

Collapse
coryjamescrook profile image
Cory Crook

So the solution for excessive node_modules is to install another npm package?

Collapse
frondor profile image
Federico Vázquez • Edited

I'd suggest rm -rf node_modules package-lock.json (don't forget package-lock.json), that little b🎺tch.

Collapse
sabz72608404 profile image
Sabz

I use rm - rf... for years and find is super fast ... Never knew about npkill will check it out

Collapse
patarapolw profile image
Pacharapol Withayasakpunt • Edited
rm -rf $(find / -type d -name node_modules) 
Enter fullscreen mode Exit fullscreen mode

It shouldn't be that hard.

Collapse
bobbyqgard profile image
Rob Gardner

Been using NPKill for a while - definitely recommend

Collapse
virejdasani profile image
Virej Dasani

What's wrong with rm -rf node_modules?

Collapse
benjaminv profile image
benjaminv

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.

Collapse
pimentelleo profile image
Leonardo Araujo Pimentel

Why not Just mv node_modules fucking_modules && npm install && rm -rf fucking_modules

Collapse
guilhermetod profile image
Guilherme Tod

Credits to Fireship?

Collapse
yaman27 profile image
Yaman Sharma Author

Credits to codevolution. But Fireship is a great channel too.

Collapse
manamelacedric profile image
Cedric

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.

Collapse
iandjx profile image
Ian de Jesus

i learned to love pnpm as alt to npm and yarn to have a central repository of all node=modules

Collapse
trangchongcheng profile image
trangchongcheng

Right mouse and choose delete :D

Collapse
shinigami92 profile image
Shinigami

@yaman27 you should add a gif to this blog article :)
That could make it a bit more clear why this is so powerfull

Collapse
yaman27 profile image
Yaman Sharma Author

Will surely do from next time. Thanks!

Collapse
vishnubhadri profile image
Vishnuraj Sivakumar

shift+del works for me...