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

@hitchy/plugin-rate-limiter

v0.2.0

Published

a Hitchy plugin for limiting request rates

Downloads

9

Readme

@hitchy/plugin-rate-limiter

Hitchy plugin for limiting request rates

License

MIT

Installation

npm install @hitchy/plugin-rate-limiter

Usage

This plugin is providing a service for generating customized policy routing handlers suitable for limiting request rates of a hitchy-based service. Thus, you can integrate it with your service in context of policy routing configuration.

In configuration file config/policies.js you could use the plugin like this:

module.exports = function() {
	const { RateLimiter } = this.runtime.service;

	return {
		policies: {
			"POST /api": [
				RateLimiter.limitPerSecond( 10 ),
				RateLimiter.limitPerMinute( 300 ),
			],
		}
	};
};

A consuming configuration file must comply with common module pattern for gaining access on services provided by this plugin as demonstrated in second line of this example.

Currently, rate limiting works per process, only. This is not a problem in most cases for Hitchy is handling all requests in a single process due to the nature of Javascript/Node.js. It becomes an issue when running several instances of your Hitchy-based application e.g. in context of a load balancer. However, in those cases we advise to configure rate limiting at load balancer as well.

API

limitPerSecond

RateLimiter.limitPerSecond( count, { queueSize = 0, retryAfter = 10, perClient = false } )

This generator creates handler accepting up to given count of requests within a rolling second. Additional requests are rejected with HTTP status code 503 suggesting to retry after given number of seconds. Either parameter must be given as number.

By defining a positive queue size, an according number of requests is deferred before rejecting additional requests.

If option perClient is true, rate limit are applied per requesting client causing separate queues being managed accordingly.

limitPerMinute

RateLimiter.limitPerMinute( count, { retryAfter = 120, perClient = false } )

This function creates handler accepting up to given count of requests within a rolling minute. Additional requests are rejected with HTTP status code 503 suggesting to retry after given number of seconds. Either parameter must be given as number.

This helper method does not support definition of a deferral queue for using it in context of a rate per minute is unusual and counterintuitive to a client expecting requests being processed in seconds at most. You might use underlying RateLimiter.limitPerTime() to have a limit per minute combined with a deferral queue.

If option perClient is true, rate limit are applied per requesting client.

limitPerHour

RateLimiter.limitPerHour( count, { retryAfter = 900, perClient = false } )

This function creates handler accepting up to given count of requests within a rolling hour. Additional requests are rejected with HTTP status code 503 suggesting to retry after given number of seconds. Either parameter must be given as number.

This helper method does not support definition of a deferral queue for using it in context of a rate per hour is unusual and counterintuitive to a client expecting requests being processed in seconds at most. You might use underlying RateLimiter.limitPerTime() to have a limit per hour combined with a deferral queue.

If option perClient is true, rate limit are applied per requesting client.

limitPerTime

RateLimiter.limitPerTime( count, { 
	timeframe = 1, 
    queueSize = 0, 
    retryAfter = 10,
    peerIdentifier = undefined,
    perClient = false,
} )

This function is the underlying generator used by those other helper functions listed above. It creates a handler accepting up to given count of requests within a rolling timeframe with its length given in seconds. Additional requests are rejected with HTTP status code 503 suggesting to retry after given number of seconds. Either parameter must be given as number.

By defining a positive queue size, an according number of requests is deferred before rejecting.

If option perClient is true, rate limits are applied per requesting client. However, this option is ignored if a custom callback has been provided as peerIdentifier which is expected to name the peer or its class of peers given either incoming request's descriptor as argument. The callback should return a string naming the peer or its class of peers. It may return a promise for that string, too.

Warning! Combine peer identification or rate limiting per client and queue sizes with great care as it may cause runtime issues due to huge memory consumption.