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

649
Visualizações
Why am I getting a warning to run fileHandle.close()?

I'm running a nodeJS program, which initially reads a db, and then writes to it, through several iterations of a for loop

(async ()=>{
const db = JSON.parse(await fs.readFile(DB_URL));
// ... more code
for(let i = 0; i < n /*n in the range of 10^3*/; i++){
  // ... manipulate the db
  // ... more code
  const dir = './FolderName';
  await fs.mkdir(dir, { recursive: true });
  await Promise.all(
    arr.map(async (arrItem, index) =>
      fs.writeFile(`${dir}/${index + 1}.png`, arrItem)
    )
  );
  await fs.writeFile(
    `${dir}/fileName.json`,
    JSON.stringify(db)
  );
}
})()

However, at random times, I'm getting this error.

(node:36680) Warning: Closing file descriptor 39 on garbage collection
(Use `node --trace-warnings ...` to show where the warning was created)
internal/process/warning:50
(node:36680) [DEP0137] DeprecationWarning: Closing a FileHandle object on garbage collection is deprecated. Please close FileHandle objects explicitly using FileHandle.prototype.close(). In the future, an error will be thrown if a file descriptor is closed during garbage collection.

I read from this answer, that fileHandle.close() is necessary only when I am opening a file using fileHandle.open(). Then what is going wrong? Why am I getting this error?

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