Question: I have a csv parser implemented as a series of transform streams:

```
process.stdin
    .pipe(iconv.decodeStream('win1252'))
    .pipe(csv.parse())
    .pipe(buildObject())
    .pipe(process.stdout);

```

I'd like to abstract the parser (in its own module) and be able to do:

```
process.stdin.
    .pipe(parser)
    .pipe(process.stdout);

```

where `parser` is just the composition of the previously used transform streams.

If I do 

```
var parser = iconv.decodeStream('win1252')
    .pipe(csv.parse())
    .pipe(buildObject());

```

then `parser` is set to the buildObject() stream and only this transformation stream receives the data.

If I do 

```
var parser = iconv.decodeStream('win1252');
parser
    .pipe(csv.parse())
    .pipe(buildObject());

```

it doesn't work either, as `.pipe(process.stdout)` will be called on the 1st transform stream and the 2 others will be bypassed.

Any recommendation for an elegant composition of streams?

Answer: 
Unfortunately, there is no built-in way to do that, but there is cool [multipipe](https://github.com/segmentio/multipipe) package. 
Use like this:

```
var multipipe = require('multipipe');

var parser = multipipe(iconv.decodeStream('win1252'), csv.parse(), buildObject());

```
As of 2022, and nodejs v16, there is a new `compose` function in the stream module, that build a Duplex stream from a list of streams.

see : <https://nodejs.org/api/stream.html#streamcomposestreams>

works with `.pipe()` and async syntax.