Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

489
Vistas
How to find all node_modules directories in a given directory and it's sub folders, then delete? (Node.js/fs)

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.");
    }

});

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda