reqlim: Request Limiting Middleware
raw JSON →reqlim is a Connect/Express middleware designed to limit incoming requests, acting as a direct adaptation of the popular `express-rate-limit` package. Its primary function is to prevent abuse by restricting the number of requests a user can make within a specified timeframe, returning a 429 'Too Many Requests' status when limits are exceeded. Despite its utility, the package remains at an early development stage with version 0.0.0 and has not seen active development since its initial publication over four years ago. This makes it an effectively abandoned project. Developers seeking a stable, actively maintained, and feature-rich rate-limiting solution for Express applications should opt for `express-rate-limit` directly, which served as the inspiration for `reqlim` and offers continuous updates, bug fixes, and better community support, including TypeScript definitions.
Common errors
error ReferenceError: require is not defined in ES module scope ↓
import syntax with a CJS interop (e.g., import rateLimit from 'reqlim';). The simplest solution is to use a modern, ESM-compatible rate limiter like express-rate-limit. error TypeError: app.use() requires a middleware function but got a undefined ↓
rateLimit function to get the actual middleware: app.use(rateLimit({ ...options })). Warnings
breaking The package version is 0.0.0, indicating it is an unstable, pre-release version. It has not been updated in over four years, meaning it is effectively abandoned and should not be used in production environments. ↓
gotcha reqlim is a CommonJS-only package. Attempting to use `import` syntax in an ESM project will result in runtime errors unless a build step or Node.js's CJS interop is properly configured. ↓
gotcha The package does not ship with TypeScript type definitions. Using it in a TypeScript project will require manually declaring types or suppressing type errors, which can lead to runtime issues. ↓
breaking Due to its abandoned status, `reqlim` will not receive security updates, bug fixes, or performance improvements. Using it could expose applications to known vulnerabilities or introduce unexpected behavior. ↓
Install
npm install reqlim yarn add reqlim pnpm add reqlim Imports
- rateLimit wrong
import rateLimit from 'reqlim'correctconst rateLimit = require('reqlim') - middleware factory wrong
app.use(rateLimit)correctapp.use(rateLimit({ windowMs: 60 * 1000, max: 5 })) - options configuration wrong
rateLimit(60000, 100)correctrateLimit({ windowMs: 60000, max: 100, statusCode: 429 })
Quickstart
const express = require('express');
const rateLimit = require('reqlim');
const app = express();
const port = 3000;
// Basic rate limiting middleware: 5 requests per minute per IP
const limiter = rateLimit({
windowMs: 60 * 1000, // 1 minute
max: 5, // Limit each IP to 5 requests per `window`
message: 'Too many requests from this IP, please try again after a minute',
headers: true, // Send rate limit info in headers
onLimitReached: (req, res, options) => {
console.log(`IP ${req.ip} has reached the limit on ${req.url}`);
}
});
// Apply the rate limiting middleware to all requests
app.use(limiter);
// Define a simple route
app.get('/', (req, res) => {
res.send('Hello World! You are being rate limited.');
});
// Start the server
app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`);
console.log('Try to make more than 5 requests in a minute to see the rate limit in action.');
});