Registry / http-networking / connect-ratelimit

connect-ratelimit

JSON →
library0.0.7jsnpmunverified

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-ratelimit
INSTALL
IMPORT
SIG · CONNECT-RATELIMIT
C
connect-ratelimit
http-networkingjavascriptv0.0.7
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

limiter
const limiter = require('connect-ratelimit');
import limiter from 'connect-ratelimit';
This package is CommonJS-only and does not support ES module `import` syntax.

Demonstrates basic rate limiting with whitelisting and custom categories using the 'connect' framework, running a simple HTTP server.

const connect = require('connect'); const http = require('http'); const limiter = require('connect-ratelimit'); const app = connect(); // Basic rate limiting: 500 requests/hour for 'normal' clients // 4000 requests/hour for 'whitelist', 0 for 'blacklist' app.use(limiter({ whitelist: ['127.0.0.1'], // Whitelist local IP blacklist: ['example.com'], // Blacklist a domain categories: { normal: { totalRequests: 5, // For demonstration, set a low limit every: 60 * 1000 // 5 requests per minute } }, end: true // Terminate middleware chain if limit exceeded (default) })); app.use(function (req, res) { res.end('Hello world! Your IP is: ' + (req.headers['x-forwarded-for'] || req.connection.remoteAddress)); }); http.createServer(app).listen(4000, () => { console.log('Connect server running on http://localhost:4000'); console.log('Try refreshing the page to hit rate limits for 127.0.0.1'); });
Debug
Known issues
breakingThis package is explicitly designed for the 'connect' framework, which is an older middleware system. Direct usage with modern Express.js applications without an explicit 'connect' compatibility layer may lead to unexpected behavior or errors.
fix
For Express.js, consider 'express-rate-limit' or 'rate-limiter-flexible'. If using 'connect', ensure your application correctly integrates 'connect' middleware.
affects: >=0.0.1
breakingThe package is version 0.0.7 and has not been updated since August 2014. It is considered abandoned and will not receive security patches, bug fixes, or compatibility updates for newer Node.js versions or evolving web standards. Using it in production is strongly discouraged.
fix
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).
affects: >=0.0.1
gotchaClient identification relies on `req.headers['x-forwarded-for']` or `req.connection.remoteAddress`. In environments behind a proxy (like Nginx, AWS ELB, etc.), `remoteAddress` will be the proxy's IP, and `x-forwarded-for` can be spoofed if the proxy isn't configured to set it correctly and securely. This can lead to incorrect rate limiting or bypasses.
fix
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.
affects: >=0.0.1
breakingThis package is a CommonJS module, requiring `require()` for inclusion. It is not directly compatible with native ES Modules (ESM) without a transpilation step or a CommonJS wrapper.
fix
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).
affects: >=0.0.1
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to import `connect-ratelimit` using ES module syntax (`import`) in a JavaScript file configured as an ES module.
fix
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.
TypeError: app.use is not a function
Using the `connect-ratelimit` middleware directly with an `express` application instance without the `connect` compatibility layer.
fix
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.
Client is not being rate limited, or is being rate limited incorrectly.
The client identification mechanism (`x-forwarded-for` or `remoteAddress`) is not accurately reflecting the true client IP, often due to improper proxy configuration or IP spoofing.
fix
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.
Upgrade
Version history
0.0.7latest on npm
Audit
Dependencies
connectrequiredThis package is a middleware specifically designed for the 'connect' framework.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
connect-ratelimit — npm install connect-ratelimit · libregistry