DEV Community

Aman Pareek
Aman Pareek

Posted on

Execute function after response sent to client - express nodejs

 app.use((req, res, next) => {
    const originalEnd = res.end;

    if (req.method !== "GET" && res.statusCode < 400) {
      res.end = function (chunk, encoding) {
        originalEnd.call(this, chunk, encoding);

        mainBuilder(); // function i want to execute
      };
    }
    next();
  });

Enter fullscreen mode Exit fullscreen mode

Explanation youtube video

Top comments (0)