PikoPong
  • Web Dev
  • Hack
  • Database
  • Big Data
  • AWS
  • Linux
No Result
View All Result
PikoPong
  • Web Dev
  • Hack
  • Database
  • Big Data
  • AWS
  • Linux
No Result
View All Result
PikoPong
No Result
View All Result
Home Web Dev

How to delete all node_modules directories from your computer

July 8, 2020
in Web Dev
286 6
How to delete all node_modules directories from your computer





How to delete all node_modules directories from your computer | Go Make Things












Go Make Things

June 17, 2020

Over the last few years, I’ve run npm install more times than I can count. And as a result, I have a lot of node_modules directories on my computer that I long forgot about and never use.

Sometimes I don’t need the project at all anymore, but often, it’s a codebase I just don’t work with often.

My node_modules directories contained 50mb of stuff on the small side, and over 200mb of files in some cases. Over a few dozen projects, that really adds up!

Yesterday, I decided to delete every single node_modules directory off of my computer, and selectively reinstall the ones I need only when I need them.

That could be a really long, arduous manual task. But fortunately for me, Mark Pieszak wrote an article about how to do it with a single command line script.

Testing first

Before doing this, it’s a good idea to test the script and make sure it’s not going to do anything you don’t want it to.

First, in a terminal/CLI window, cd into whatever directory contains most of your code projects. On my Mac, that’s sites. Your setup might be different.

Then, run this code.

# Mac/Linux
find . -name "node_modules" -type d -prune -print | xargs du -chs

# Windows
FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" echo %d"

This will spit out a list of all of the node_modules that it finds, and how much disk space they’re taking up (individually and in total).

Actually deleting files

If you’re happy with what the script finds, you can now delete all of the directories off of your computer.

# Mac/Linux
find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' ;

# Windows
FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" rm -rf "%d"

And that’s that. Thanks to Mark and the Trilon folks for documenting this!

Like this? I send out a short email each weekday with code snippets, tools, techniques, and interesting stuff from around the web. Join 9,400+ daily subscribers.


Made with ❤️ in Massachusetts. Unless otherwise noted, all code is free to use under the MIT License. I also very irregularly share non-coding thoughts.



Source link

Share219Tweet137Share55Pin49

Related Posts

On Auto-Generated Atomic CSS | CSS-Tricks
Web Dev

On Auto-Generated Atomic CSS | CSS-Tricks

Robin Weser’s “The Shorthand-Longhand Problem in Atomic CSS” in an interesting journey through a tricky problem. The point is...

January 15, 2021
How to Add Commas Between a List of Items Dynamically with CSS
Web Dev

3 Approaches to Integrate React with Custom Elements

In my role as a web developer who sits at the intersection of design and code, I am drawn...

January 15, 2021
Community Resources, Weekly Newsletter, And Boosting Skills Online — Smashing Magazine
Web Dev

Smashing Workshops & Audits — Smashing Magazine

About The AuthorJuggling between three languages on a daily basis, Iris is known for her love of linguistics, arts,...

January 15, 2021
4 Lessons Web App Designers Can Learn From Google — Smashing Magazine
Web Dev

The Report — Smashing Magazine

About The AuthorSuzanne Scacca is a former WordPress implementer, trainer and agency manager who now works as a freelance...

January 15, 2021
Next Post
How to Make a List Component with Emotion

How to Make a List Component with Emotion

Using GitHub Actions for MLOps & Data Science

Introducing the GitHub Availability Report

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended

Push deploy a Laravel app for free with GitHub Actions

May 24, 2020

Be Kind, Be Curious (November 2020 Wallpapers Edition) — Smashing Magazine

October 31, 2020
A CSS Grid Framework For Shopify Collection Pages — Smashing Magazine

A CSS Grid Framework For Shopify Collection Pages — Smashing Magazine

September 22, 2020
Make Jamstack Slow? Challenge Accepted.

Make Jamstack Slow? Challenge Accepted.

July 15, 2020

Categories

  • AWS
  • Big Data
  • Database
  • DevOps
  • IoT
  • Linux
  • Web Dev
No Result
View All Result
  • Web Dev
  • Hack
  • Database
  • Big Data
  • AWS
  • Linux

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In