Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!