Skip to content

A simple and efficient rate limiting middleware for Express applications, designed to help protect your API from excessive use and ensure fair usage.

License

Notifications You must be signed in to change notification settings

ayoubezzini/throttle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rate Limiting Middleware for Express

A simple and efficient rate limiting middleware for Express applications, designed to help protect your API from excessive use and ensure fair usage. This package uses an in-memory store by default for tracking request counts, making it easy to integrate and use out of the box.

Features

  • Easy Integration: Seamlessly integrates with any Express application.
  • In-Memory Store: Comes with a built-in in-memory store for IP-based rate limiting.
  • Configurable Limits: Allows customization of request limits and window times.
  • Extendable: Designed to be extendable for use with external stores like Redis for distributed applications.

Usage

First, install the package using npm:

import express from 'express';
import { rateLimiter } from '@yi/throttle';

const app = express();
const PORT = 3000;

// Apply rate limiting middleware
app.use(rateLimiter({
  windowMs: 15 * 60 * 1000, // 15 minutes
  maxRequests: 100, // Limit each IP to 100 requests per windowMs
}));

app.get('/', (req, res) => {
  res.send('Hello, World!');
});

app.listen(PORT, () => {
  console.log(`Server running on http://localhost:${PORT}`);
});

API

  • rateLimiter(options): RequestHandler Creates and returns the rate limiting middleware.

Options

  • windowMs: Number of milliseconds for each rate limiting window (default: 15 minutes).
  • maxRequests: Maximum number of requests allowed per window per IP (default: 100).

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A simple and efficient rate limiting middleware for Express applications, designed to help protect your API from excessive use and ensure fair usage.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published