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

nodebalancer

v0.9.2

Published

Load balancing and reverse proxy app for microservices infrastructure and REST APIs

Downloads

9

Readme

nodebalancer

A simple node.js load balancer and reverse proxy to be used in a RESTful or mirrored/distributed microservices architecture.

Balances and proxies HTTP requests addressed to a web service provider host towards a list of mirror servers; upon receiving HTTP or socket errors redirects the request to the next host in the stack, in order to provide high availability and uptime of services and REST APIs. Can be run on the same machine on different configurations passing by argument a JSON file containing a list of servers to be proxied and the port to be run on.

Install

With npm do:

npm install nodebalancer -g

Usage

A new proxy instance can be run using the command:

node nodebalancer.js ./config.json 1234

A new listener will be opened on port 1234, using the server list read from the file config.json, on the local machine under the application path. If a port number is not provided, port 8000 is used as a default. If the file is not a valid JSON or is not present under the path an error will be raised.

To start the proxy using https it is possible to use the flag -s; in this case, the path to the server key can be specified using the flag -k, and the one to the server certificate using the flag -c; An example:

node nodebalancer.js ./config.json 1234 -s -k /etc/ssl/key.pem -c /est/ssl/cert.pem

Key and certificate default to key.pem and cert.pem under the process working root.

Configuration file

A configuration file is a JSON file containing in a JSON array a list of JSON objects, each containing hosts and ports to be mirrored. It is possible to explicit the protocol to be used for the request, could be http or https (defaults to http), in this form:

[   {
		"host": "localhost",
		"port": 7800
	},
	{
		"host": "testserver1",
		"port": 4444,
		"protocol" : "https"
	},
	{
		"host": "abc.test.com",
		"port": 1234,
		"protocol" : "http"
	}
]

Behavior

Assuming that each proxied host contains the same resources, invoking an HTTP verb on the machine running nodebalancer results in a round-robin load balancing of the requests. In case an error occurs, for example because the invoked resource does not exist on the host, or the socket connection cannot be established because of a downtime due to failure or mantainance, the request in redirected to the next host in the list.

It is supposed that the requests are completely stateless, hence sessionization should be provided server-side, having knowledge of the high availability tool used on top of the stack.

Running the module different times, using different configuration files and/or different ports is useful in order to have a reverse proxy for each resource that should be kept in high availability.

Contribution

If you want to contribute or if you spot a bug (or just have questions) please feel free to open an issue on github or email me at [email protected]

Changelog

v0.9.1 28/02/18 - log caller address, request id

v0.9.0 08/11/17 - added https support, improved error handling

v0.1.6 02/05/17 - first stable release including descriptions

v0.2.1 03/05/17 - added TTL to avoid endless loops

v0.2.3 08/05/17 - added config file error handling

v0.2.3 08/05/17 - added executable in package.json

v0.2.5 09/05/17 - fixed bug on binary server responses

v0.2.6 09/05/17 - improved error handling on startup

v0.3.0 10/05/17 - added support for HTTP request body, fixed method issues