Skip to content

Instantly share code, notes, and snippets.

@liesislukas
Created July 15, 2019 16:23
Show Gist options
  • Save liesislukas/809b4e94edae9b46d084568271f417b8 to your computer and use it in GitHub Desktop.
Save liesislukas/809b4e94edae9b46d084568271f417b8 to your computer and use it in GitHub Desktop.
express nodejs after response listener sample
app.use(function (req, res, next) {
function afterResponse() {
res.removeListener('finish', afterResponse);
res.removeListener('close', afterResponse);
var log = logger.loggerInstance.child({
id: req.id
}, true)
log.info({res:res}, 'response')
}
res.on('finish', afterResponse);
res.on('close', afterResponse);
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment