Introducing through2

In notebook:
FrontEndMasters Networking and Streams
Created at:
2017-09-24
Updated:
2017-10-01
Tags:
backend Node JS JavaScript libraries

through2 is a module you can install with npm:

$ npm install through2 // ☛ or add -s

or you can use stream.Transform from node core. This is how it would look like with the newer core interface:

var Transform = require('stream').Transform // import it
// or import it from npm ↴
var Transform = require('readable-stream').Transform


// ☛ there's also a finish function (what should happen when the stream
// is done with

var toUpper = new Transform({ // ☛ need to call with new
  transform: function (buf, enc, next) {
    next(null, buf.toString().toUpperCase())
  }
})

process.stdin
  .pipe(toUpper)
  .pipe(process.stdout)