# miniget

> A small HTTP(S) GET request library, with redirects and streaming.

Latest version **4.2.3** (published 2023-06-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install miniget
pnpm add miniget
yarn add miniget
bun add miniget
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.2.3 |
| Published | 2023-06-23 |
| First published | 2017-04-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 28.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 57 |
| Author | fent |
| Maintainers | fent |
| Keywords | request, http, https, redirect, stream |

## Links

- npm: https://www.npmjs.com/package/miniget
- Repository: https://github.com/fent/node-miniget
- Homepage: https://github.com/fent/node-miniget#readme
- Issues: https://github.com/fent/node-miniget/issues
- npm.io page: https://npm.io/package/miniget

## 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

- 4.2.3 (latest) — 2023-06-23
- 4.2.2 — 2022-01-09
- 4.2.1 — 2021-05-27
- 4.2.0 — 2021-02-02
- 4.1.0 — 2020-11-24
- 4.0.0 — 2020-11-21
- 3.1.1 — 2020-11-21
- 3.1.0 — 2020-11-16
- 3.0.0 — 2020-11-13
- 2.1.0 — 2020-11-03
- 2.0.2 — 2020-10-24
- 2.0.1 — 2020-07-01
- 2.0.0 — 2020-05-30
- 1.7.2 — 2020-05-26
- 1.7.1 — 2020-05-25
- … 13 more at https://npm.io/package/miniget/versions

## README

# node-miniget

A small http(s) GET library with redirects, retries, reconnects, concatenating or streaming, and no dependencies. This keeps filesize small for potential browser use.

![Depfu](https://img.shields.io/depfu/fent/node-miniget)
[![codecov](https://codecov.io/gh/fent/node-miniget/branch/master/graph/badge.svg)](https://codecov.io/gh/fent/node-miniget)


# Usage

Concatenates a response

```js
const miniget = require('miniget');

miniget('http://mywebsite.com', (err, res, body) => {
  console.log('webpage contents: ', body);
});

// with await
let body = await miniget('http://yourwebsite.com').text();
```

Request can be streamed right away

```js
miniget('http://api.mywebsite.com/v1/messages.json')
  .pipe(someWritableStream());
```


# API

### miniget(url, [options])

Makes a GET request. `url` can be a string or a `URL` object. `options` can have any properties from the [`http.request()` function](https://nodejs.org/api/http.html#http_http_request_options_callback), in addition to

* `maxRedirects` - Default is `10`.
* `maxRetries` - Number of times to retry the request if there is a 500 or connection error. Default is `2`.
* `maxReconnects` - During a big download, if there is a disconnect, miniget can try to reconnect and continue the download where it left off. Default is `0`.
* `backoff` - An object with `inc` and `max` used to calculate how long to wait to retry a request. Default is `{ inc: 100, max: 10000 }`.
* `highWaterMark` - Amount of data to buffer when in stream mode.
* `transform` - Use this to add additional features. Called with the object that `http.get()` or `https.get()` would be called with. Must return a transformed object.
* `acceptEncoding` - An object with encoding name as the key, and the value as a function that returns a decoding stream.
  ```js
  acceptEncoding: { gzip: () => require('zlip').createGunzip(stream) }
  ```
  Given encodings will be added to the `Accept-Encoding` header, and the response will be decoded if the server responds with encoded content.

Defaults are held in `miniget.defaultOptions` and can be adjusted globally.

Miniget returns a readable stream, errors will then be emitted on the stream. Returned stream has additional methods added, and can emit the following events.

### Stream#destroy([error])

Destroys the request.

### Stream#destroyed

Set to `true` after `Stream#destroy()` has been called.

### Stream#text()

Returns a promise that resolves to the concatenated contents of the response.

```js
let body = await miniget('http://yourwebsite.com').text();
```

#### Event: redirect
* `string` - URL redirected to.

Emitted when the request was redirected with a redirection status code.

#### Event: retry
* `number` - Number of retry.
* `Error` - Request or status code error.

Emitted when the request fails, or the response has a status code >= 500.

#### Event: reconnect
* `number` - Number of reconnect.
* `Error` - Request or response error.

Emitted when the request or response fails after download has started.

#### Event: request
* [`http.ClientRequest`](https://nodejs.org/api/http.html#http_class_http_clientrequest) - Request.

Emitted when a video request is made, including after any redirects, retries, and reconnects.

#### Event: response
* [`http.ServerResponse`](https://nodejs.org/api/http.html#http_class_http_serverresponse) - Response.

Emitted when a video response has been found and has started downloading, including after any successful reconnects.

#### Forwarded events

Any events emitted from the [request](https://nodejs.org/api/http.html#http_class_http_clientrequest) or [response](https://nodejs.org/api/http.html#http_class_http_serverresponse) objects will be forwarded to the miniget stream.

# Install

    npm install miniget


# Tests
Tests are written with [mocha](https://mochajs.org)

```bash
npm test
```

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