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

@dws-std/elysia-ratelimit

v1.0.0

Published

Rate limiting plugin for Elysia framework.

Readme

🚦 DWS Elysia Rate Limit

Rate limiting for Elysia routes, guards, and groups, as a macro.
Drop rateLimit on any endpoint and abusive traffic gets cut before it ever hits your logic.

Why this package?

This plugin uses Elysia's macro system to add rate limiting to any route, guard, or group.
You add rateLimit: { limit: 10, window: 60 } and you're done.

By default it limits by client IP, which works great for auth endpoints.
For cases where many users share the same public IP (offices, corporate proxies), you can pass a keyGenerator to rate limit by IP + access token, session ID, API key, or any combination that makes sense.

Storage is handled by @dws-std/kv-store, so you start with in-memory and move to Redis when you need to, without changing your routes.

📌 Table of Contents

✨ Features

  • 🎯 Per-route macros : Attach rateLimit to any route independently, with its own limit and window.
  • 🔑 Custom key generation : Rate limit by IP (default), IP + token, session, or any key you compute.
  • 🗃️ KvStore-agnostic : Works with MemoryStore out of the box; swap in BunRedisStore or your own adapter.
  • Early rejection : Runs in transform, the first per-route hook, before auth guards and handlers.
  • 📡 Standard headers : Automatically sets X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset.

🔧 Installation

bun add @dws-std/elysia-ratelimit

Peer dependencies: elysia must be installed alongside.

⚙️ Usage

Basic - rate limit by IP

The simplest form: pass limit (max requests) and window (time in seconds). Each client IP gets its own counter.

import { rateLimitPlugin } from '@dws-std/elysia-ratelimit';
import { Elysia } from 'elysia';

new Elysia()
	.use(rateLimitPlugin())
	.post('/auth/login', () => authenticate(), {
		rateLimit: { limit: 10, window: 60 } // 10 requests per minute per IP
	})
	.listen(3000);

Custom store - Redis

By default, counters are kept in memory. Pass a BunRedisStore (or any KvStore adapter) for persistence across restarts and multi-instance deployments.

import { BunRedisStore } from '@dws-std/kv-store';
import { rateLimitPlugin } from '@dws-std/elysia-ratelimit';
import { Elysia } from 'elysia';

const store = new BunRedisStore('redis://localhost:6379');

new Elysia()
	.use(rateLimitPlugin(store))
	.post('/auth/login', () => authenticate(), {
		rateLimit: { limit: 10, window: 60 }
	})
	.listen(3000);

Custom key generation - IP + access token

Useful for authenticated routes where many users share the same public IP (office, corporate proxy).
Each user has their own counter, independent of their network.

import { rateLimitPlugin } from '@dws-std/elysia-ratelimit';
import { Elysia } from 'elysia';

new Elysia()
	.use(rateLimitPlugin())
	.get('/api/data', () => getData(), {
		rateLimit: {
			limit: 100,
			window: 60,
			keyGenerator: ({ ip, request }) => `${ip}:${request.headers.get('authorization') ?? ip}`
		}
	})
	.listen(3000);

Tip: extractClientIp is exported if you need it inside your own keyGenerator.

📚 API Reference

Full docs: Dominus-Web-Service.github.io/packages

⚖️ License

MIT — see LICENSE.md.

📧 Contact

Maintained by Dominus Web Services.