Registry / http-networking / rate-limit-memcached

rate-limit-memcached

JSON →
library1.0.1jsnpmunverified

rate-limit-memcached is a specialized storage adapter designed for the `express-rate-limit` middleware, enabling distributed rate limiting using a Memcached server. It is currently at version 1.0.1, indicating a stable and mature state after its initial 1.0.0 release. The package is actively maintained within the `express-rate-limit` ecosystem, though a specific release cadence is not formally stated. Its key differentiator is providing an efficient, externalized state management solution for rate limiting, making it suitable for applications deployed across multiple instances where local memory stores are insufficient. It integrates seamlessly with the core `express-rate-limit` package, providing configuration options for Memcached server locations and custom client instances, ensuring flexibility for various deployment scenarios.

npm install rate-limit-memcached
INSTALL
IMPORT
SIG · RATE-LIMIT-MEMCACH
R
rate-limit-memcached
http-networkingjavascriptv1.0.1
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.

MemcachedStore
import { MemcachedStore } from 'rate-limit-memcached'
const MemcachedStore = require('rate-limit-memcached')
Primarily designed for ESM. While CommonJS might work via transpilation, direct `require` can lead to issues with named exports.
rateLimit
import { rateLimit } from 'express-rate-limit'
const rateLimit = require('express-rate-limit')
This is a peer dependency; ensure it's imported from `express-rate-limit`.
MemcachedStoreOptions
import type { MemcachedStoreOptions } from 'rate-limit-memcached'
Type import for configuring the store, useful for TypeScript projects.

Demonstrates initializing `express-rate-limit` with `rate-limit-memcached` for distributed rate limiting across an Express application, using environment variables for Memcached host.

import express from 'express'; import { rateLimit } from 'express-rate-limit'; import { MemcachedStore } from 'rate-limit-memcached'; const app = express(); // Ensure a Memcached server is running at localhost:11211 or specified locations const limiter = rateLimit({ windowMs: 15 * 60 * 1000, // 15 minutes max: 100, // Limit each IP to 100 requests per window standardHeaders: 'draft-7', legacyHeaders: false, store: new MemcachedStore({ // Optional: The prefix attached to all keys stored in Memcached prefix: 'rl:', // The server location(s), passed directly to Memcached client constructor locations: [process.env.MEMCACHED_HOST || 'localhost:11211'], // Optional: Pass a custom Memcached client instance instead of default // client: myCustomMemcachedClient }), }); // Apply the rate limiting middleware to all requests app.use(limiter); app.get('/', (req, res) => { res.send('Hello, you are rate limited!'); }); const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`); console.log('Ensure Memcached is running, e.g., `memcached -p 11211`'); });
Debug
Known issues
breakingThis package requires Node.js version 16 or above. Older Node.js versions are not supported and may lead to runtime errors.
fix
Upgrade your Node.js environment to version 16 or higher.
affects: <1.0.0
gotchaThis store requires a running Memcached server instance. If no server is accessible at the configured `locations`, the rate limiter will fail to store and retrieve counts, potentially leading to uncaught errors or unexpected behavior.
fix
Ensure Memcached is installed and running at the specified `locations` (default `localhost:11211`). Verify network connectivity and firewall rules if Memcached is remote.
affects: >=1.0.0
breakingThe `express-rate-limit` peer dependency must be version 6 or greater. Earlier versions are not compatible and will result in installation warnings or runtime errors.
fix
Install or upgrade `express-rate-limit` to a version `>= 6.0.0`.
affects: <1.0.0
gotchaIf you don't provide a custom `client` option to `MemcachedStore`, the package internally instantiates the `memcached` npm package. Ensure `memcached` is accessible if you rely on this default behavior.
fix
If you encounter issues with the default client, consider installing `memcached` directly, passing your own `Memcached` client instance, or debugging the default client's connection via the `locations` and `config` options.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: MemcachedStore is not a constructor
Attempting to import `MemcachedStore` using CommonJS `require()` syntax or incorrect destructuring in an ESM context.
fix
Use `import { MemcachedStore } from 'rate-limit-memcached';` for ES Modules. Ensure your project is configured for ESM if using `type: module` in `package.json`.
Memcached connection error: Connection refused
The Memcached server is not running or is not accessible at the specified `locations`.
fix
Start your Memcached server (e.g., `memcached -p 11211`). Verify the `locations` array in `MemcachedStore` options. Check firewall settings or network connectivity for remote servers.
npm ERR! ERESOLVE unable to resolve dependency tree
The `express-rate-limit` peer dependency version requirement is not met by other installed packages or is missing.
fix
Install `express-rate-limit` explicitly: `npm install express-rate-limit@^6`. If conflicts persist, try `npm install --force` (use with caution) or `npm install --legacy-peer-deps`.
ReferenceError: require is not defined
Attempting to use `require()` in an ES Module context without proper setup or bundler transformation.
fix
Convert your project to use ES Modules by adding `"type": "module"` to your `package.json` and using `import` statements, or configure your bundler (Webpack, Rollup, etc.) to handle CommonJS modules.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
express-rate-limitrequiredRequired as the core rate limiting middleware.
memcachedoptionalUsed as the default Memcached client if none is provided via the `client` option.
Agent activity
12 hits · last 30 days
node
10
Meta
1
Resources
rate-limit-memcached — npm install rate-limit-memcached · libregistry