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 🙏

© 2025 – Pkg Stats / Ryan Hefner

vhost-delegator

v0.3.0

Published

Delegate the server work to other nodeJS applications by routing based on subdomains

Downloads

10

Readme

vhost-delegator

vhost-delegator is a proxy server which routes requests to other nodejS applications based on domain name.

Installation

npm install vhost-delegator

##Server

The vhost-delegator runs as an http server, by default on port 80, which proxies the connections to other nodeJS applications, on the same server, but with different port numbers. The server can be started like this:

var delegator = require('vhost-delegator');

delegator.startServer({});

Options

The options object passed to the startServer method looks like this:

{
  //these are the options for the controller, which the clients communicate with
  controller: {
    //port the controller runs on. The clients must be given the same port when they start
    port: 8080,
    //username and password which clients must use to be authorized as apps. 
    username: "admin",
    passowrd: "admin",
    //range of ports which the clients can run on. The maxmum numbr of simultanious clients is determined by the size of this list
    appPorts: [5060, 5061]
  },
  //these are the options for the proxy server
  delegator: {
    //outward port the server runs on
    port: 80
  }
}

Events

Once a delegator server has been started, it emits events about what happens. The following events are emitted

  • app-started: Emitted when a client connects. The parameter is the app object, containing the name, port and address to the client app.
  • app-stopped: Emitted when a client disconnects. The parameter is app object, containing the name, port and address to the client.
  • error: Emitted when an error occures. The parameter is an object with a code, describing the error, and a message with details about the error. The following errors can occure:
    • NAME_CONFLICT: A client has attempted to connect as an app that already exists. The client receives a 409 response
    • PORTS_EXHAUSTED: There are no more ports for clients to use. The client receives a 503 response

##Client

Clients connect to the server, gives the vhost name they want to run as, and in return are given a port number to run under. Only when they are given the port number should they start the http server:

var delegator = require('vhost-delegator');
var server = require('http');

var server = http.createServer(function(req, res){
  res.end("hello");
});
 
delegator.startClient("mysite.localhost", {}, server);

Options

The options object passed to the startClient method looks like this:

{
  //the controller hostname
  host: 'localhost',
  //port of the controller. Matches the controller.port option used when starting the server
  port: 8080,
  //username and password sent to the controller. Must match the controller.username and controller.password options used when starting the server
  username: "admin",
  passowrd: "admin"
}

Events

The startClient method returns an object which emits events. The following events are emitted:

  • started: Emitted when the client has connected to the server and has been given a port. The event is called with the port as the only argument.
  • stopped: Emitted when the client has disconnected from the server.
  • error: Emited when something bad happens. The parameter is an object with a code, describing the error, and a message with details about the error. The following errors can occure:
  • START_REJECTED: The server did not accept the client, either because a client with that name already exists, or because there is no more resources (ports) for more clients