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

@chabdulwahab/flowcap

v1.0.4

Published

Zero-dependency, framework-agnostic rate limiting middleware. Cap the flow.

Readme

Rate limiting, the way it should've been

@chabdulwahab/flowcap

A zero-dependency, framework-agnostic HTTP rate limiting middleware for Node.js.

NPM Version NPM Downloads Dependencies Types: Included Node.js Support License: MIT


Features

  • Framework Agnostic: Seamlessly integrates with Express, Fastify, Koa, and vanilla Node.js HTTP modules.
  • Zero Dependencies: No external runtime dependencies, minimizing security risks and bundle sizes.
  • Human-Readable Windows: Configure durations using intuitive strings like '15m', '30s', or '1h'.
  • High Performance: Implements an in-memory sliding window algorithm with O(1) automatic pruning.
  • Built-in Presets: Includes pre-configured rule sets (login, api, strict, loose) for common scenarios.
  • Standards Compliant: Follows the IETF draft-8 standard for RateLimit headers.
  • First-Class TypeScript Support: Out-of-the-box type declarations included.

Installation

npm install @chabdulwahab/flowcap

Usage

Express

const express = require('express');
const flowcap = require('@chabdulwahab/flowcap');

const app = express();

// Apply a global rate limit of 100 requests per minute
app.use(flowcap({ limit: 100, window: '1m' }));

Built-in Presets

Presets provide default configurations for common use cases. These settings can be overridden.

// Protect login route (5 req / 15m)
app.post('/login', flowcap.login());

// Standard API limit (100 req / 1m)
app.use('/api', flowcap.api());

// Strict limit for administrative routes (20 req / 1m)
app.post('/admin', flowcap.strict());

// Loose limit for public assets (500 req / 1m)
app.get('/public', flowcap.loose());

// Override a preset configuration
app.post('/login', flowcap.login({ limit: 3 }));

Framework Support

Fastify

const fastify = require('fastify')();
const flowcap = require('@chabdulwahab/flowcap');

fastify.use(flowcap());

Koa

const Koa = require('koa');
const flowcap = require('@chabdulwahab/flowcap');

const app = new Koa();

app.use(async (ctx, next) => {
  return new Promise((resolve) => {
    flowcap()(ctx.req, ctx.res, () => resolve(next()));
  });
});

API Reference

Configuration Options

| Option | Type | Default | Description | | --- | --- | --- | --- | | limit | number | 100 | Maximum requests permitted per window. | | window | string | number | '1m' | Window duration. Accepts readable strings (e.g., '15m', '30s') or milliseconds. | | keyBy | function | req => req.ip | Extracts the unique identifier for the client making the request. | | skip | function | null | Returns true to unconditionally bypass rate limiting. | | onLimit | function | null | Custom handler for HTTP 429 Responses: (req, res, next). | | legacyHeaders | boolean | true | Appends traditional X-RateLimit-* headers alongside IETF draft-8 standards. | | store | Store | Memory | Instance of a custom state store. |

Advanced Configurations

Custom Client Identification

app.use(flowcap({
  limit: 200,
  window: '1h',
  keyBy: (req) => req.headers['x-api-key'] || req.ip
}));

Conditional Bypassing

app.use(flowcap({
  limit: 100,
  window: '1m',
  skip: (req) => req.path === '/health'
}));

Custom Rate Limit Responses

app.use(flowcap({
  limit: 50,
  window: '30s',
  onLimit: (req, res, next) => {
    res.status(429).json({ error: 'Rate limit exceeded. Please try again later.' });
  }
}));

Custom Store Implementation

For distributed environments (e.g., Redis), implement the FlowcapStore interface and pass the instance to options.store.

interface FlowcapStore {
  count(key: string, windowMs: number): number;
  add(key: string, windowMs: number): void;
  resetTime(key: string, windowMs: number): number;
}

Resources

  • Deep Dive / Article: Read the detailed article on dev.to explaining the design decisions and implementation details behind Flowcap.

License

MIT