I am using 'morgan' library to log my request, time it takes and the size of response.
But, for a POST request is there a way I can log the POST request and its body size when it is received?
After going through morgan documentation for about an hour I found a good solution to the problem.
Instead of using morgan-body, logging can can be done using the morgan library itself at the time of request. Even the length of the POST body can be logged quite easily.
Here is how it can be done:
app.use(morgan({format: 'POST body length in bytes :req[Content-Length]', immediate: true}))
Here the 'format' option defines the format of log and the 'immediate' option writes the log at the time request is received