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

koa-karma-proxy

v1.0.0-pre.5

Published

Simplified coordination of karma and upstream proxy server using the koa web framework.

Downloads

102

Readme

koa-karma-proxy

Simplified coordination of karma and upstream proxy server using the koa web framework.

Overview

This project came about because of the need to run a proxy server to perform on-demand transformations to responses from a karma server. In principle this is straightforward as long as the karma and proxy server ports were reliably fixed. When configuring karma, you have to be able to tell it what port the upstream proxy server is running on-- and you have to know what port the karma server is running on to direct requests from the proxy server.

The problem is that karma does not have a reliably fixed port, because karma will search for an available port when the default one is in use and then bind to that. Because of the mutual dependency on port knowledge between karma and the proxy server, some magic is required to slot in the karma server's address into the running proxy server after it starts up.

This library coordinates this process behind the scenes so your setup doesn't require a bunch of boilerplate with listeners and hooks to wire everything up.

Usage

First, you'll need to install it, most likely as a devDependency of your npm package/application:

$ npm install --save-dev koa-karma-proxy

Create a file called karma.proxy.js and export a function that returns a Koa app, which will define your proxy server. Be sure to slot in the provided proxy to karma, which is the single given parameter, named "karma" in the example below:

const Koa = require('koa');
const someMiddleaware = require('./some-middleware.js');
module.exports = (karma) => new Koa().use(someMiddleware).use(karma);

In the following example, we'll use the koa-node-resolve package to translate node bare module specifiers to relative paths on-the-fly. Please note that we mount the nodeResolve middleware specifically to the /base sub-path, since that is where karma serves our test, source and node_modules files from:

const Koa = require('koa');
const mount = require('koa-mount');
const {nodeResolve} = require('koa-node-resolve');
module.exports = (karma) => new Koa()
    .use(mount('/base', nodeResolve())
    .use(karma);

Use the karma-proxy wrapper script exactly as you'd use karma executable:

$ npx karma-proxy start

This will:

  1. find an open port for the proxy server.
  2. start the proxy server, listening on that port.
  3. start karma. (identical to karma start)
  4. wait for karma to confirm the port it is listening on.
  5. configure the proxy middleware to start directing requests to karma.

The wrapper supports two optional flags in addition to all the ones in the standard karma CLI:

  • --proxyFile to point to a file other than karma.proxy.js.
  • --proxyAddress to specify a host name/IP for the proxy to listen on other than the default 0.0.0.0.
  • --proxyHostname to specify a host name/IP to direct browsers to other than the default localhost.
  • --proxyPort to specify a starting port other than the default 9876 to start the upstream proxy server on.

Please note, when using npx, flags given to karma-proxy should follow a -- separator so they are not treated as npx flags:

$ npx karma-proxy start -- --proxyFile ./lib/my-proxy.js --proxyPort 30330

Advanced Usage

You don't have to use karma-proxy as an executable from the command-line. It exposes everything you need to leverage within your own code:

const Koa = require('koa');
const mount = require('koa-mount');
const {join} = require('path');
const {start} = require('koa-karma-proxy');
const {nodeResolve} = require('koa-node-resolve');

(async () => {
  const {upstreamProxyPort, karmaPort} =
    await start((karma) => new Koa()
      .use(mount('/base', nodeResolve())
      .use(karma), {
        // Karma config options
        configFile: join(__dirname, '../karma.conf.js'),
        singleRun: true
      });
  console.log(`Upstream Port ${upstreamProxyPort}`);
  console.log(`Karma Port ${karmaPort}`);
})();