# stream-forward

> Forward stream events.

Latest version **3.0.0** (published 2015-08-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install stream-forward
pnpm add stream-forward
yarn add stream-forward
bun add stream-forward
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2015-08-19 |
| First published | 2015-07-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | stephenplusplus |
| Keywords | stream, forward, event |

## Links

- npm: https://www.npmjs.com/package/stream-forward
- npm.io page: https://npm.io/package/stream-forward

## Dependencies (2)

- [stubs](https://npm.io/package/stubs.md) ^2.0.0
- [arrify](https://npm.io/package/arrify.md) ^1.0.0

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 3.0.0 (latest) — 2015-08-19
- 2.0.1 — 2015-08-17
- 2.0.0 — 2015-07-12
- 1.0.0 — 2015-07-07

## README

# stream-forward

> Forward events to the next stream in the pipeline.

## Use

```sh
$ npm install --save stream-forward
```
```js
var streamForward = require('stream-forward');
```

## Example

```js
var streamForward = require('stream-forward');
var request = require('request');

var opts = {
  events: ['response']
};

streamForward(request('http://yahoo.com'), opts)
  .pipe(process.stdout)
  .on('response', function (response) {
    // `response` from the request stream.
  });
```

**Note: don't neglect proper event handling on the individual parts of your stream.**

This is just a convenience when you have to manually listen and re-emit events across a middleman/spy pipe. Consider the following example:

```js
var fs = require('fs');

function getRequestStream(reqOpts) {
  var opts = {
    events: ['complete']
  };

  return streamForward(request(reqOpts), opts)
    .pipe(fs.createWriteStream('./request-cache'));
}

getRequestStream('http://yahoo.com')
  .on('complete', function () {
    // Without `stream-forward`, this couldn't emit.
  });
```

## stream = streamForward(stream, [options]);


### stream

Type: `Stream`

The source stream to spy on. This is returned from the function to allow chaining.


### options

*Optional.* Configuration options.


#### options.continuous

Type: `Boolean`
<br>Default: `false`

If true, when a new stream is attached to `stream`, it will receive the events emitted by the original.

##### Disabled (default)
```js
var sourceStream = request('http://yahoo.com');
var through = require('through2');

streamForward(sourceStream)
  .pipe(through())
  .on('complete', function () {
    // Called.
  })
  .pipe(through())
  .on('complete', function () {
    // Not called.
  });
```

##### Enabled
```js
var sourceStream = request('http://yahoo.com');
var through = require('through2');

streamForward(sourceStream, { continuous: true })
  .pipe(through())
  .on('complete', function () {
    // Called.
  })
  .pipe(through())
  .on('complete', function () {
    // Called.
  });
```


#### options.events

Type: `Array`

Event names to re-emit on attached streams.

---
_Source: https://npm.io/package/stream-forward · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
