connect-ratelimit is a Connect middleware designed to limit the number of requests per client IP address or hostname to a Node.js server. As of its last known update, it is at version 0.0.7, indicating a very early stage of development and a likely abandoned status, with no new releases since August 2014. It distinguishes clients using `req.headers['x-forwarded-for']` or `req.connection.remoteAddress` and supports flexible rate limiting rules through configurable 'normal', 'whitelist', and 'blacklist' categories. Uniquely, it offers an `end` option to either prematurely terminate the middleware chain with a 'Rate limit exceeded' message or allow the chain to continue, augmenting the `response` object with rate limit details for custom handling. This package is built for the `connect` framework, which is less commonly used directly in modern Node.js web applications, often replaced by frameworks like Express. Its core differentiation lies in its direct integration with `connect`'s simple middleware pattern and its customizable category-based limiting, though newer, more robust alternatives exist for current Node.js ecosystems.
npm install connect-ratelimitVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic rate limiting with whitelisting and custom categories using the 'connect' framework, running a simple HTTP server.
For Express.js, consider 'express-rate-limit' or 'rate-limiter-flexible'. If using 'connect', ensure your application correctly integrates 'connect' middleware.
Migrate to a actively maintained rate-limiting solution like 'express-rate-limit' (for Express) or 'rate-limiter-flexible' (for more general Node.js use cases).
Ensure your proxy infrastructure correctly sets and forwards client IP headers. For more robust identification, consider rate limiters that integrate with other client attributes (e.g., authenticated user IDs, API keys) or use a trusted proxy solution.
If your project uses native ESM, you will need to use a compatible modern rate-limiting library. If you must use this package, ensure your project is configured for CommonJS or use dynamic `import()` within an async context (though this is not recommended for an abandoned package).
This package is CommonJS-only. Either convert your consuming file to CommonJS (`.js` without `"type": "module"` in `package.json`) and use `const limiter = require('connect-ratelimit');`, or use a modern rate-limiting library compatible with ESM.Ensure you are either using the `connect` framework directly (`const app = connect();`) or, if using Express, consider `express-rate-limit` which is designed for Express. If you must use this middleware with Express, you'd typically wrap it: `app.use(connect().use(limiter(...)));` which is generally not recommended.
Verify that your proxy (e.g., Nginx, cloud load balancer) is correctly forwarding client IP addresses via the `X-Forwarded-For` header and that your Node.js application is trusting these headers. Also consider using a more modern rate-limiting solution that supports various client identification strategies.