# request-multi-streams

> Make multiple http requests. Receive response progress indicators, pipe streams.

Latest version **0.0.5** (published 2019-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install request-multi-streams
pnpm add request-multi-streams
yarn add request-multi-streams
bun add request-multi-streams
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2019-02-19 |
| First published | 2017-01-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 16.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Luis Antunes |
| Maintainers | luisantunesdeveloper |
| Keywords | http, download, request, streams, multiple, multiple-streams, multi-streams |

## Links

- npm: https://www.npmjs.com/package/request-multi-streams
- Repository: https://github.com/luisantunesdeveloper/request-multi-streams
- Homepage: https://github.com/luisantunesdeveloper/request-multi-streams#readme
- Issues: https://github.com/luisantunesdeveloper/request-multi-streams/issues
- npm.io page: https://npm.io/package/request-multi-streams

## Dependencies (2)

- [request](https://npm.io/package/request.md) ^2.79.0
- [request-progress](https://npm.io/package/request-progress.md) ^3.0.0

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.0.5 (latest) — 2019-02-19
- 0.0.4 — 2017-01-04
- 0.0.3 — 2017-01-04
- 0.0.2 — 2017-01-04
- 0.0.1 — 2017-01-04
- 0.0.0 — 2017-01-03

## README

# request-multi-streams

[![Build Status](https://travis-ci.org/luisantunesdeveloper/request-multi-streams.svg?branch=master)](https://travis-ci.org/luisantunesdeveloper/request-multi-streams)
[![Test Coverage](https://codeclimate.com/github/luisantunesdeveloper/request-multi-streams/badges/coverage.svg)](https://codeclimate.com/github/luisantunesdeveloper/request-multi-streams/coverage)

This library wraps multiple http get requests using request/request and IndigoUnited/node-request-progress to different locations at the same time. The streams are handed and can be piped as they come, along with the progress. You can even repeat a request multiple times.

## Install

npm i request-multi-streams

## Usage

See examples and tests to get more detail about the requests and responses.

### Requests

Since this module wraps request and request-progress, it supports the same options for both.

```sh
const req1 = {
  options: {
    url: 'https://cdn.pixabay.com/photo/2014/03/27/21/10/waterfall-299685_1280.jpg'
  },
  numberOfRequests: 1000 // Not the same as retries
};

const req2 = {
  options: {
    url: 'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcS2bZdzOUGStsuLVzH79PTGHMoJ0B_ZpUcJylVdveVd4p5oyywvSCRaHSg'
  },
  progressOptions: {
    throttle: 0,                    // Throttle the progress event to 2000ms, defaults to 1000ms
    delay: 10,                       // Only start to emit after 1000ms delay, defaults to 0ms
    // lengthHeader: 'x-transfer-length'  // Length header to use, defaults to content-length
  },
  numberOfRequests: 10 // Not the same as retries, request-multi-streams internal usage.
};

// receives an array of requests
const streamEmitters = httpMultiStreams.streams([req1, req2]);
```

### Responses

You can do whatever you want with the streams. In this case we are piping the streams for the request name 'http://www.textfiles.com/fun/acronym.txt' to a file. See examples folder for more info.

```sh
for(var name in emitters) {
  //listen the events
  emitters[name].on('progress', (data) => {
    console.log(chalk.yellow(`Request ${data.reqNumber} for ${data.args.options.url}: ${Number((data.progress.percent * 100).toFixed(1))}% complete`));
  });

  emitters[name].on('response', (data) => {
    console.log(chalk.yellow(`Request ${data.reqNumber} for ${data.args.options.url}: got a response`));
    if (name === 'http://www.textfiles.com/fun/acronym.txt') {
      data.stream.pipe(fs.createWriteStream(`${__dirname}/${data.reqNumber}`));
    }
  });
}
```

### Major dependencies

https://www.npmjs.com/package/request  
https://www.npmjs.com/package/request-progress

### Works with node > 4.5

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