dnode: Search and Delete Node Modules Folders Recursively

Source: github.com/akshaybabloo/dnode

Node’s package managers makes it easy to develop applications, but the bloat it brings with it is (that’s node_modules) painful. My 2013 Mac with 256 GB HDD cannot handle it. I currently have around eight projects that use yarn package manager and the total size of all node_modules comes to around ~2.2GB. And let's not even get to the cache folder (Tip: yarn cache clean). All the hate for node_modules is totally justified.

All I want to do is to delete all unused node_modules folders (we all think that we will get back to it at some point but we never do), and there are different ways to do it:

  1. Go to each project and delete the node_modules folder
  2. Use one of the following shell scripts:
  • Windows:
FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" rm -rf "%d"
  • Linux:
find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;
  • PowerShell
Get-ChildItem -Path "." -Include "node_modules" -Recurse -Directory | Remove-Item -Recurse -Force

3. Or use dnode:

dnode delete

Instillation

There are pre-built binaries for Windows, macOS and Linux, these can be found at the release page.

Or you could build one yourself:

Note: The code depends on Go 1.17 or above

git clone https://github.com/akshaybabloo/dnode.git
cd dnode
go build -o dnode
./dnode --help

Usage

There are two commands — list and delete.

List

dnode list lists all the unused node_modules folders in the current directory tree.

Example:

Delete

dnode delete deletes all the unused node_modules folders in the current directory tree.

Example:

Final Thoughts

Again, this CLI was developed out of frustration to get rid of unused node_modules folders. I hope you find it useful.

Happy coding 🍾

Originally posed at:

--

--

--

PhD student, currently doing research on Spiking Neural Networks and Brain Computer Interfaces

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

Recommended from Medium

Let’s talk about testing

How to Break into Software Development: The Ultimate Guide for University & College Students (2022)

S3 Code Pipelines to Promote & Deploy Lambda Microservices

Audius, DODO, Livepeer, mStable, Opyn, PoolTogether, Reflexer, and UMA Go Live on The Graph Network

#3 Bermuda 🔺 election — What’s coming 🎃?

Building technology solutions with distributed development team: communication challenges

Installing a CouchDB 2.1.1 server on Ubuntu 16.04 with SSL.

Value types and exceptions in .NET profiling

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
Akshay Gollahalli

Akshay Gollahalli

PhD student, currently doing research on Spiking Neural Networks and Brain Computer Interfaces

More from Medium

Golang Installation on Ubuntu

How To Install And Setup Go Language On Ubuntu (Complete Guide)

How To Install And Setup Go Language On Ubuntu (Complete Guide)

Simple IoT Messages Delivery With GoLang — 2

Golang Logging Deep Data Structure with go-spew