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

105
Views
express middleware after response

I've had a problem with middleware function which is launching on finish execution of main function from endpoint. Here is my middleware:

export const someMiddleware = async (
    req: Request,
    res: Response,
    next: NextFunction
) => {
    res.on("finish", () => {
        //here
    })
    next();
}

I am having trouble getting the data that was sent to the client from the request handled by this middleware, can anyone tell me how to get the response body that is sent to the client inside the on () callback?

Thanks for any help!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is quite painful with Express. One way to handle this is to override the send and write functions, and capture the output this way.

It's not impossible to do this, other middlewares like a gzip middleware would do this too.

A frustration with this limitation has eventually lead me to write my own framework, so I get where you are coming from.

about 4 years ago · Juan Pablo Isaza Report
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!