npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

request-multi-streams

v0.0.5

Published

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

Downloads

12

Readme

request-multi-streams

Build Status Test 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.

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.

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