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

express-brute-guard

v1.0.0

Published

A customizable and production-ready rate-limiting middleware for Node.js.

Readme

🛡️ Express-Brute-Guard

A lightweight, customizable, and production-ready rate-limiting middleware for Node.js, designed to protect APIs from brute-force and abuse attacks. Built with in-memory storage and optional headers, with support for auto-cleanup of expired IP entries.


🚀 Features

  • 🔒 Per-IP rate limiting
  • ⏲️ Configurable request window and block duration
  • ⚡ Fast in-memory store
  • 📡 Customizable response headers
  • 🧹 Auto cleanup of expired entries (no cron needed)
  • 🧱 Pluggable store system (Redis/DB support planned for v2)

📦 Installation

bash

npm install express-brute-guard

📚 Usage

typescript

import express from 'express';
import { BruteGuard } from 'express-brute-guard';

const app = express();

const bruteGuard = new BruteGuard({
  maxRequests: 5,
  windowMs: 10 * 60 * 1000, // 10 minutes
  blockDuration: 5 * 60 * 1000, // 5 minutes
  errormessage: 'Too many attempts. Please try again later.',
  headers: true, // Add X-RateLimit-* headers
});

// Apply middleware
app.use((req, res, next) => bruteGuard.createGuard(req, res, next));

// Your routes
app.get('/', (req, res) => {
  res.send('Welcome!');
});

app.listen(3000, () => console.log('Server running on port 3000'));

📦 Default Export (Plug & Play Middleware)

If you just want to use BruteGuard with default or minimal config:

typescript

import bruteGuard from 'express-brute-guard';
import express from 'express';

const app = express();

// Apply brute-force protection globally
app.use(bruteGuard.createGuard());

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

✅ Best for: Quick setup and global protection.

⚙️ Named Export (Custom Configs per Route)

If you need custom configurations (e.g., different rate limits per route):

typescript

import { BruteGuard } from 'express-brute-guard';
import express from 'express';

const app = express();

// Create multiple instances with custom configs
const loginLimiter = new BruteGuard({
  maxRequests: 5,
  windowMs: 60 * 1000, // 1 minute
});

const signupLimiter = new BruteGuard({
  maxRequests: 2,
  windowMs: 5 * 60 * 1000, // 5 minutes
});

// Apply per-route brute-force protection
app.post('/login', loginLimiter.createGuard(), (req, res) => {
  res.send('Login route');
});

app.post('/signup', signupLimiter.createGuard(), (req, res) => {
  res.send('Signup route');
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

🔧 Best for: Apps needing fine-grained control, customization, or testing.


⚙️ Options

| Option | Type | Default | Description | | --------------- | --------- | --------------------- | ----------------------------------------------------- | | maxRequests | number | 10 | Max requests allowed before blocking | | windowMs | number | 5 * 60 * 1000 | Time window for tracking requests (in ms) | | blockDuration | number | 3 * 60 * 1000 | How long to block the IP after limit exceeded (in ms) | | statusCode | number | 429 | HTTP status code for blocked requests | | errormessage | string | 'Too many Requests' | Message shown when limit is exceeded | | headers | boolean | true | Whether to set rate-limit headers | | store | any | memoryStore | Optional custom store (e.g., Redis support in v2) |


🧠 How It Works

  • Each IP gets tracked on request.
  • If requests exceed maxRequests in windowMs, IP is temporarily blocked.
  • If an entry expires, it is automatically cleaned up by a background process using setInterval.

🔮 Coming in v2

  • ✅ Redis store support
  • ✅ Sliding window algorithm
  • ✅ Per-route configuration
  • ✅ Type-safe middleware usage
  • ✅ Dashboard / monitoring integration

🧪 Testing

Basic test setup (optional):

bash
npm install --save-dev jest supertest

You can write tests to validate:

  • Blocking after limit
  • Reset after window
  • Cleanup behavior

🤝 Contributing

PRs and feature requests are welcome! Open issues or reach out via GitHub.

🧑‍💻 Author

Developed by Taran Mesala

For support or feature requests, open an issue.


📄 License

This project is licensed under the MIT License.