Use the debug module on a stream
npm install debug-stream
var debugStream = require('debug-stream')('my-app')
process.stdin
.pipe(debugStream())
.resume() // just drain it
// or if you're already using debug
var debug = require('debug')('my-app')
var debugStream = require('debug-stream')(debug)
process.stdin
.pipe(debugStream())
.resume()
Running the above program with DEBUG=*
will use the debug module on every line
in the stream. If the stream is an object stream it will run debug on every object in the stream.
You can add an optional format string as well
var debugStream = require('debug-stream')('my-app')
process.stdin
.pipe(debugStream('process.stdin: %s'))
.resume() // just drain it
The debug stream behaives as pass through stream so can just insert it in any existing pipe chain
inputStream
.pipe(debugStream())
.pipe(outputStream)
MIT