DEV Community

Cover image for How to delete all node_modules folder in system !!!
uttesh
uttesh

Posted on • Updated on

How to delete all node_modules folder in system !!!

Most of the time once the project is completed, we will move to different projects leaving the old project folder in the system without any cleanup.

Nodejs application or npm based application node_modules will take a lot of system memory and eventually our system memory will dry up, its not easy task to find and remove all node_modules in one go.

Wrote simple CLI to do this clean that's "mo-clean", its a simple CLI that finds the all node_modules in the system by root path and provides the details like memory taken, last used time, and path. after getting all information it will remove those node_modules from the system.

Alt Text

Alt Text

What it does?

It identifies the unused node_modules of NodeJS application based on last used by days and provides the details

  1. When the project was last used.
  2. How much memory node_modules taken.
  3. Remove those node_modules from system.

How to use

Just install the library, don't clone this repository and run! (you can do that but not required)

Installation

Please install the package with the flag '-g'.

 npm install -g mo-clean
Enter fullscreen mode Exit fullscreen mode

Execution

Run the below command from the command prompt/terminal

> mo
Enter fullscreen mode Exit fullscreen mode

that will prompt the user with the below options for the search or delete the node_modules

  __  __    ___
 |  \/  |  / _ \
 | |\/| | | | | |
 | |  | | | |_| |  _   _   _
 |_|  |_|  \___/  (_) (_) (_)

? Please select an option:

 1) Search all the node_modules present in the path and show the total memory taken?

 2) Search and delete all the node_modules present in the path?

 Enter the option(1 or 2):
Enter fullscreen mode Exit fullscreen mode

after the option selected it will prompt the path for the search or delete

Search Option

It will search for all the node_modules present under the provided path.

demo

Remove Option

It will search all the node_modules present under the provided path and delete them.

demo

Github Link: https://github.com/uttesh/mo

Top comments (2)

Collapse
 
davidkartuzinski profile image
David Kartuzinski

Hi! I tried it on my mac. Installing Mo is fine, but it nevers stops searching, even if I point it to my Repos folder. Like /Users/david/repos

In your example you use the c: is that necessary?

Collapse
 
utteshkumar profile image
uttesh

Resolved the Linux related issued of the CLI, it's working fine on the Linux, I guess that should be fine with Mac as well.
If anyone used it on Mac please add comments.