Duplex stream that reads/writes from/to multiple duplex streams at once
npm install multi-duplex-stream
Below is a minimal example of running ssh commands in parallel:
'use strict'
var ssh = require('ssh-exec')
var eos = require('end-of-stream')
var multiDuplex = require('multi-duplex-stream')
module.exports = function pssh (hosts, cmd, cb) {
var sshStreams = hosts.map(function (host) {
var stream = ssh(cmd, host)
return stream
})
var psshStream = multiDuplex.obj(sshStreams)
eos(psshStream, cb)
return psshStream
}