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 🙏

© 2026 – Pkg Stats / Ryan Hefner

multi-proxy

v0.0.12

Published

Proxy for multi endpoints

Readme

multi-proxy

npm version Build Status Coverage Status

multi-proxy is a simple proxy to send requests to multiple destinations and reduces responses to a single response.

Contents

Getting started

Install this via npm then use as a middleware of senchalabs/connect.

npm install --save multi-proxy

See fully example inside /example directory of this repository.

How it works

multi-proxy can be used as a connect middleware. You can initialize it with:

  • Patterns to forward a request
  • Destination servers

For example, this code sets up multi-proxy to 3 destinations including master server. If a request matches the one in patterns, the request is sent to all destinations and responses from them will be reduced to the one from master server.

# Initialise proxy with patterns and destinations
var multiProxy = require('multi-proxy');
var serversWithMaster = {
  master: `http://localhost:3000`,
  replica: [
    `http://localhost:3001`,
    `http://localhost:3002`
  ]
};
var patterns = [
  { method: 'GET', path: /^\/my\.index\/my\.type/ },
  { method: 'GET', path: /^\/another\.index\/another\.type/ },
  { method: 'GET', path: /^\/nothing/ }
];
var proxy = new ProxyServer(serversWithMaster, patterns);

# Set up your connect app
var connect = require('connect');
var app = connect();
app.use(multiProxy(servers, patterns));

var http = require('http');
http.createServer(app).listen(8000);

master mode

Here is the figure how it works by master mode and code example as it was introduced.

NOTICE: You can see fully example inside /example directory of this repository.

                      ┌──────────────────┐
                      │                  │
                      │      Client      │
                      │                  │
                      └────────▲──┬──────┘
                                  │
                               │  │  1. POST /something/nice
                                  │
                      ┌────────┴──▼──────┐
                      │                  │
                      │   multi-proxy    │
                      │                  │
                      └────────▲──┬──────┘
                                  │
 3. By master mode,            │  │  pattern: {
    only response from master     │    method: "POST",
    will be returned           │  │    path: /^\/something/.+/
                                  │  }
                               │  ▼
                                Λ
                               ╱ ╲   2. Only matched request
                              ▕   ▏     is forwarded to destinations
                               ╲ ╱
                              ▲ V
         ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─  │
        │ ┌─────────────────────┼─────────────────────┐
          │                     │                     │
┌───────┴─▼────────┐  ┌─────────▼────────┐  ┌─────────▼────────┐
│                  │  │                  │  │                  │
│      master      │  │    replica_a     │  │    replica_b     │
│                  │  │                  │  │                  │
└──────────────────┘  └──────────────────┘  └──────────────────┘
# Initialise proxy with patterns and destinations
var multiProxy = require('multi-proxy');
var serversWithMaster = {
  master: `http://localhost:3000`,
  replica: [
    `http://localhost:3001`,
    `http://localhost:3002`
  ]
};
var patterns = [
  { method: 'GET', path: /^\/my\.index\/my\.type/ },
  { method: 'GET', path: /^\/another\.index\/another\.type/ },
  { method: 'GET', path: /^\/nothing/ }
];
var proxy = new ProxyServer(serversWithMaster, patterns);

# Set up your connect app
var connect = require('connect');
var app = connect();
app.use(multiProxy(servers, patterns));

var http = require('http');
http.createServer(app).listen(8000);

replica mode

In replica mode, multi-proxy doesn't have master server as a destination.

It has only some replicas as destinations and if every status code from replicas is the same, it returns a reduced single response from replicas. The response is the one which has been got at first. Requests are sent to all replicas but the response to client is the one.

If every status code is not the same, it returns 500 response to the client.

                          ┌──────────────────┐
                          │                  │
                          │      Client      │
                          │                  │
                          └────────▲──┬──────┘
                                      │
                                   │  │  1. POST /something/nice
                                      │
                          ┌────────┴──▼──────┐
                          │                  │
                          │   multi-proxy    │
                          │                  │
                          └────────▲──┬──────┘
                                      │
3. Only if all status code         │  │  pattern: {
   from responses are the same,       │    method: "POST",
   return a response from replicas │  │    path: /^\/something/.+/
                                      │  }
                                   │  ▼
                                    Λ
                                   ╱ ╲   2. Only matched request
                                  ▕   ▏     is forwarded to destinations
                                   ╲ ╱
                                    V ▲
                                    │  ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
              ┌─────────────────────┼─────────────────────┐ │
              │                     │                     │
    ┌─────────▼────────┐  ┌─────────▼────────┐  ┌─────────▼─┴──────┐
    │                  │  │                  │  │                  │
    │    replica_a     │  │    replica_b     │  │    replica_c     │
    │                  │  │                  │  │                  │
    └──────────────────┘  └──────────────────┘  └──────────────────┘
# Initialise proxy with patterns and destinations
var multiProxy = require('multi-proxy');
var serversWithoutMaster = {
  replica: [
    `http://localhost:3001`,
    `http://localhost:3002`
  ]
};
var patterns = [
  { method: 'GET', path: /^\/my\.index\/my\.type/ },
  { method: 'GET', path: /^\/another\.index\/another\.type/ },
  { method: 'GET', path: /^\/nothing/ }
];

# Set up your connect app
var connect = require('connect');
var app = connect();
app.use(multiProxy(servers, patterns));

var http = require('http');
http.createServer(app).listen(8000);

Logger

You can configure your own logging config. See below:

var LOGTYPE = require('multi-proxy').LOGTYPE;

// level should be the one of levels of https://github.com/nomiddlename/log4js-node
var loggerConfig = {
  type: LOGTYPE.DATEFILE,
  level: log4js.levels.DEBUG
};
app.use(multiProxy(servers, patterns, loggerConfig));

The logger is based on log4js-node