Merge multiple streams into one stream in sequence or parallel.
Clone or download
Latest commit d2f2183 Oct 13, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
test v1.2.3 Oct 13, 2018
.gitignore support ES modules Sep 9, 2017
.travis.yml add License to package.json, #20 May 4, 2018
LICENSE Fixed for Duplex stream, #19 Jan 9, 2018 use ES6, test in Node.js 8 Jul 2, 2017
index.js v1.2.3 Oct 13, 2018
index.mjs v1.2.3 Oct 13, 2018
package-lock.json v1.2.3 Oct 13, 2018
package.json v1.2.3 Oct 13, 2018


Merge multiple streams into one stream in sequence or parallel.

NPM version Build Status Downloads


Install with npm

npm install merge2


const gulp = require('gulp')
const merge2 = require('merge2')
const concat = require('gulp-concat')
const minifyHtml = require('gulp-minify-html')
const ngtemplate = require('gulp-ngtemplate')

gulp.task('app-js', function () {
  return merge2(
        .pipe(minifyHtml({empty: true}))
          module: 'genTemplates',
          standalone: true
      ), gulp.src([
const stream = merge2([stream1, stream2], stream3, {end: false})
stream.add(stream4, stream5)
// equal to merge2([stream1, stream2], stream3)
const stream = merge2()
stream.add([stream1, stream2])
// merge order:
//   1. merge `stream1`;
//   2. merge `stream2` and `stream3` in parallel after `stream1` merged;
//   3. merge 'stream4' after `stream2` and `stream3` merged;
const stream = merge2(stream1, [stream2, stream3], stream4)

// merge order:
//   1. merge `stream5` and `stream6` in parallel after `stream4` merged;
//   2. merge 'stream7' after `stream5` and `stream6` merged;
stream.add([stream5, stream6], stream7)
// nest merge
// equal to merge2(stream1, stream2, stream6, stream3, [stream4, stream5]);
const streamA = merge2(stream1, stream2)
const streamB = merge2(stream3, [stream4, stream5])
const stream = merge2(streamA, streamB)


const merge2 = require('merge2')



merge2(stream1, stream2, ..., streamN)

merge2(stream1, stream2, ..., streamN, options)

merge2(stream1, [stream2, stream3, ...], streamN, options)

return a duplex stream (mergedStream). streams in array will be merged in parallel.


mergedStream.add(stream1, [stream2, stream3, ...], ...)

return the mergedStream.

mergedStream.on('queueDrain', function() {})

It will emit 'queueDrain' when all streams merged. If you set end === false in options, this event give you a notice that should add more streams to merge or end the mergedStream.


option Type: Readable or Duplex or Transform stream.


option Type: Object.

  • end - Boolean - if end === false then mergedStream will not be auto ended, you should end by yourself. Default: undefined

  • objectMode - Boolean . Default: true

objectMode and other options(highWaterMark, defaultEncoding ...) is same as Node.js Stream.


MIT © Teambition