DEV Community

Cover image for Delete node_modules like a Pro

Delete node_modules like a Pro

⚡ Nirazan Basnet ⚡ on April 05, 2021

Usually, while working on multiple projects we complain about the hard drive which is mystically always full. Whenever we start a new project and ...
Collapse
 
ianwijma profile image
Ian Wijma

Not sure what is wrong with rm -r node_modules

Collapse
 
nirazanbasnet profile image
⚡ Nirazan Basnet ⚡ • Edited

Nothing is wrong here. With your code, we can delete just within a project, but to delete all the node_modules from the device we can use about code. Thanks!

Collapse
 
qm3ster profile image
Mihail Malo

I recommend github.com/tbillington/kondo instead.
It's fast, is a single tiny executable (thanks, Rust), doesn't come with its own node_modules, and supports not only npm projects.

Collapse
 
nirazanbasnet profile image
⚡ Nirazan Basnet ⚡ • Edited

Didn't know about this. Thanks for sharing I will definitely try this :)

Collapse
 
zivtamary profile image
Info Comment hidden by post author - thread only accessible via permalink
Ziv Tamary

You literally just coped everything from this video, even the title. shame
youtube.com/watch?v=qOSH2pYg6m8

Collapse
 
harshvats2000 profile image
HARSH VATS

It's not wrong to convert a video to an article but he should have at least given some credit to the video :(

Collapse
 
matthijsewoud profile image
⚡️ • Edited

Doesn't npm intelligently link already-installed-elsewhere modules? If so, deleting node-modules folders might be detrimental.

Edit: whoops! I was wrong about this one, sorry gang. Maybe I got it confused with Yarn or some other package managers? If anyone knows more about this, that'd be awesome; I feel bad about having loads of copies of the same module at multiple locations on my system.

Collapse
 
pahund profile image
Patrick Hund

That's the first time I'm hearing this. To my knowledge, every npm project has its own node_modules directory and every package dependency is installed per project. Do you have a link that documents what you are suggesting?

Collapse
 
tisdadd profile image
Michael Adsit

This was my first time hearing this as well. I know that pnpm is meant to do so.

Collapse
 
john__olson profile image
John Olson

Your last suggestion of npx npkill is the easiest to use. Nothing to install.

 
itachiuchiha profile image
Itachi Uchiha

I didn't use PowerShell. But it seems a Powershell statement. Right? :P

Thread Thread
 
sarvasana profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
Kris Kater • Edited

🤮

Collapse
 
mohdahmad1 profile image
Mohd Ahmad • Edited

Check rimraf it is fast, and it is not limited to node_modules. It is written in JS so can be used in node projects

Collapse
 
mariocalin profile image
Mario

Whats is wrong with npm prune?

Collapse
 
tyanick profile image
Tazoh Yanick

Can we run the command npx npkill from any directory or we must run from the root in order to delete all node_modules files from the device?

Collapse
 
nirazanbasnet profile image
⚡ Nirazan Basnet ⚡

Didn't know about this, thanks for sharing!

Collapse
 
nirazanbasnet profile image
⚡ Nirazan Basnet ⚡

Yes !! It really helped me :)

Collapse
 
mlaraki profile image
mlaraki

You've literally copied eveything, even the title ... The least you can do is aknowledge the real author in your article !

Collapse
 
foro profile image
Foro

Was looking for the name of the package... Npkill was the name... Thanks 🤙

Some comments have been hidden by the post's author - find out more