Home

Awesome

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 codecov

Usage

Concatenates a response

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

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, in addition to

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.

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

Event: redirect

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

Event: retry

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

Event: reconnect

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

Event: request

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

Event: 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 or response objects will be forwarded to the miniget stream.

Install

npm install miniget

Tests

Tests are written with mocha

npm test