Emit the response size as an event. Monkey patches an instance of
Class:http.ServerResponse
to emit a size
event before end.
If you're using streams and want the size of a response, consider using size-stream instead.
$ npm install emit-response-size
const resSize = require('emit-response-size')
const httpNdjson = require('http-ndjson')
const stdout = require('stdout-stream')
const http = require('http')
const pump = require('pump')
http.createServer(function (req, res) {
resSize(res)
const httpLogger = httpNdjson(req, res)
pump(httpLogger, stdout)
res.on('size', function (size) {
httpLogger.setSize(size)
res.setHeader('Content-Length', size)
})
res.setHeader('Content-Type', 'text/plain')
res.end('hello world')
})
Patch a res
object to emit a 'size'
event before ending.
Listen to a 'size'
event on a response. Emitted before the 'close'
event.