0

I just recently was introduced to fs as I'm somewhat of a novice. My goal is to write a program to find all node_modules folders within a given directory and it's subfolders. For example, I have a directory that holds all of my project directories and in each of those I have node_modules directories I would like to clean up regularly by writing my own tiny program using fs & node, so I can navigate to the directory (or any directory) and run my command to delete these for me on the fly instead of trying to use file explorer to delete all which usually just locks up Windows Explorer altogether.

I've figured out the simplest form of this which is just going into that directory specifically and deleting. But I need to search all subfolders, find the node_modules directories, and then delete them all.

Here is what I've implemented that works, but only for the given directory I am currently in.

import fs from 'fs-extra';

const folder = './node_modules';

fs.remove(folder, err => {

    if (err) {
        console.log("You messed up ya dummy, so read this ---> ", err);
    } else {
        console.log("You deleted those gosh darn node thingys. Congrats, you're a genuis.");
    }

});
Josh
  • 1

0 Answers0