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

300
Views
response a file from buffer, the request is made twice to be downloaded

I have an express nodejs server which does some calculations and creates a pdf file and sends it as the response. the problem is, when the user tries to download the file, the endpoint is called twice by the browser so the calculations are done twice and it will take twice as long and it will take around 20 seconds for the request to be answered . i checked and saw that the endpoint itself is called twice not favicon.ico or other things.

the file is not saved on the server and is created as buffer and then piped to the client. and the endpoint is not called by the frontend code or fetched by something, it is just opened in a new tab in the browser. some of the codes are listed below:

let buffer =  await createPdfBuffer() // a custom function that creates the pdf as buffer
const readStream = new stream.PassThrough();
    readStream.end(buffer);
    res.set('Content-disposition', 'attachment; filename=' + file.pdf);
    res.set('Content-Type', 'application/pdf');
    readStream.pipe(res);

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!