OMBD#15: The Only Command You Need To Know To Wipe Out Your node_modules

Welcome to issue #15 of One Minute Better Developer, where you become a more successful software developer by reading short nuggets of knowledge, one minute at a time.

⏮️ 🔛 ⏭️


You want to do a backup of all your current files because you’re switching computers.

Some of your local repositories have unpublished branches so you want to copy them over to your new machine rather than checking out their remote versions.

However, the gazillion files inside node_modules make copying the repo take 2 hours. You don’t want to go on every directory and delete the folder manually.

What do you do?


We are going to use Unix's find to look for node_modules folders in our repositories directory, and then we are going to use xargs to pass these paths to rm.

  1. Go into your repositories directory:
cd <your_repositories_dir_path>

2. List the node_modules directories you are going to remove:

find . -type d -name node_modules# ./example-repo/node_modules
# ./example-repo/node_modules/node-libs-browser/node_modules
# ...

3. Let’s use xargs to pass these paths to rm :

find . -type d -name node_modules | xargs rm -rf

4. Done! let’s double-check that all the node_modules have been deleted:

find . -type d -name node_modules# Empty

Now copying over our repositories directory to our new machine takes just a second, and we can run npm install to generate a new node_modules directory.

If you liked this story, you may also like:

Full-Stack Developer, Teacher, Maker, and general Things-Doer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Building React Native Projects with Native Code: Part 5

Server-Side Development with Fastify — Route Declarations

How does javaScript works 😵? How is JS single-threaded and asynchronous?

Create Graphics with Voronoi Diagram with the Visx Library

Create a Pass the Message App with Vue 3 and JavaScript

Maintainable JavaScript — CSS and JavaScript

Node.js Best Practices — Scaling and Technology

Announcing Fastify v4 release candidate!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jon Portella

Jon Portella

Full-Stack Developer, Teacher, Maker, and general Things-Doer.

More from Medium

vsce support

How to Debug js/ts jest

Change VS Code “Find” Search Result Highlight Color