Express connection / middleware that runs after a response is sent to the client

Is it possible to write middleware that runs after a response is sent to the client or after the request is processed and called immediately before the response is sent to the client?

+8
middleware express connect
source share
2 answers

pauljz gave a basic method, but to extend it, here is an example of middleware

module.exports = function() { return function(req, res, next) { req.on("end", function() { // some code to be executed after another middleware // does some stuff }); next(); // move onto next middleware } } 

In the main application

 expressApp.use(require("./doneMiddleware")); expressApp.use(express.logger()); expressApp.use(express.static..... 
+13
source share

See if there will be a binding to req.on('end', function() {...}); for you.

+3
source share

All Articles