I’m using node.js and express to handle HTTP requests and responses. By using the http.ServerRequest event, I can add a hook in and log HTTP requests. There doesn’t seem to be a similiar event for http.ServerResponse and I am wondering how to log all the HTTP responses with one piece of code that my server sends?
I’m using node.js and express to handle HTTP requests and responses. By using the
Share
I created a package that does such a thing, out of a similar need. Check out express-request-logger
The heart of the program is like this, it contains some extra code so you can have your own key-value map of data that gets logged per request:
The above code runs as middleware in express. Take a look at the code, and if you have further questions, get in touch with me on here or github.