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

98
Visualizações
Push fs / chokidar data to array

I was using chokidar for the first time and I was trying to get all the file names in a directory and push them to an array. Chokidar successfully gets the file names but when I push them to array the names are not being registered. Or maybe they are being registered then being overwritten by an empty path when chokidar checks for updates. Either way, how can I get all the file names in an array. Any help is appreciated. Thanks in advance.

const chokidar = require('chokidar');

var currentData = []
chokidar.watch('./dirPATH').on('all', (event, path) => {
  //what I tried
  if (path != '' && path != ' ' && path != null && path != undefined) {
    currentData.push(path);
  }
  console.log(path) //prints path correctly
});


console.log(currentData) //prints empty array
//expected print array with items of file names aquired by chokidar

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