Express middleware before response is carried out to client
Well you can override the send function:
app.use(function (req, res) { var send = res.send; res.send = function (body) { // It might be a little tricky here, because send supports a variety of arguments, and you have to make sure you support all of them! // Do something with the body... send.call(this, body); };});
If you want to support more than just calling send
(like calling end
method), then you have to override more functions...
You can check connect-livereload on how it adds a script to any html output.
Your lack of code makes it really hard to answer your question, but you could use something like
Express 4.0:router.use('/path', function (req, res) { // Modify req});
.use
on a route will parse that before continuing on to the actual route so if somebody submitted a form or something, it will hit the .use
before it goes to the .post
or .get
Or you can do
Express 4.0:app.use(function (req, res) { // Modify Req if (req.body.hasOwnProperty('some_form_name')) { // Do Somthing }});
Which is the same thing, but it will be called before every request for every route.
Not sure if this answers your question but I think this might be what you're looking for?