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

193
Views
Why does my code does not download the zip file in Nodejs

I Have been building a server which is gonna give out a zip file to download. It does not download the first time. But the second time it downloads. I use jimp to edit images and output those files into a specific directory.

app.use(
    '/api/edit',
    upload.single('image-file'),
    async (req, _res, next) => {
        const filePath = path.resolve(process.cwd(), 'user-data', req.file.filename);
        
        // resize every images
        await resizeAll(filePath);

        // continue request
        next();
    }
);

app.post('/api/allResize', upload.single('image-file'), (_req, res) => {
    // use res.setHeader to set the application file type to zip
    setHeaderAsZip(res);

    const zip = archiver('zip');
    zip.pipe(res);

    zip.directory('./user-data/icon-set-imagable', 'icon-set-imagable').finalize();

    res.on('close', () => {
        cleanUpIconData();
    });
});

The first time it generates the resizeAll output it sends a empty zip file but the second time it sends the file but do the cleanUpIconData, which clears out all data generated in the server.

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!