Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

495
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda