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

310
Vistas
How to catch createReadStream error in node js?

It's been 3 days struggling to catch an error in fs.createReadStream. There is a file when I try to unzip it it stuck while extracting and doesn't throw any error. Below is my code for reference:

const unzip = require("unzip-stream"),
function extractFileAndParse(file) {
  return new Promise(function (resolve, reject) {
    let extractedDirName = file.replace(".zip", "");
    let unzipPipe = unzip.Extract({
      path: `./directory/${extractedDirName}`,
    });
    try {
      let stream = fs.createReadStream(`${directory}/${file}`).pipe(unzipPipe);
      stream.on("finish", function () {
        return resolve({
          contentid: extractedDirName,
        });
      });
      stream.on("error", (err) => {
        return reject();
      });
    } catch (error) {
      console.log("Error occurred while parsing the file: ", error);
      reject();
    }
  });
}

For a normal file, once the extraction is done it goes to finish event and return the resolve(). But couldn't catch an error if it get stuck (or I don't know it doesn't throw an error) while extracting. Any idea why? Thanks!

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