{"library":"rate-limit-memcached","title":"Memcached Store for express-rate-limit","description":"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.","language":"javascript","status":"active","last_verified":"Thu Apr 23","install":{"commands":["npm install rate-limit-memcached"],"cli":null},"imports":["import { MemcachedStore } from 'rate-limit-memcached'","import { rateLimit } from 'express-rate-limit'","import type { MemcachedStoreOptions } from 'rate-limit-memcached'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import express from 'express';\nimport { rateLimit } from 'express-rate-limit';\nimport { MemcachedStore } from 'rate-limit-memcached';\n\nconst app = express();\n\n// Ensure a Memcached server is running at localhost:11211 or specified locations\nconst limiter = rateLimit({\n\twindowMs: 15 * 60 * 1000, // 15 minutes\n\tmax: 100, // Limit each IP to 100 requests per window\n\tstandardHeaders: 'draft-7',\n\tlegacyHeaders: false,\n\tstore: new MemcachedStore({\n\t\t// Optional: The prefix attached to all keys stored in Memcached\n\t\tprefix: 'rl:', \n\t\t// The server location(s), passed directly to Memcached client constructor\n\t\tlocations: [process.env.MEMCACHED_HOST || 'localhost:11211'], \n\t\t// Optional: Pass a custom Memcached client instance instead of default\n\t\t// client: myCustomMemcachedClient\n\t}),\n});\n\n// Apply the rate limiting middleware to all requests\napp.use(limiter);\n\napp.get('/', (req, res) => {\n  res.send('Hello, you are rate limited!');\n});\n\nconst PORT = process.env.PORT || 3000;\napp.listen(PORT, () => {\n  console.log(`Server running on http://localhost:${PORT}`);\n  console.log('Ensure Memcached is running, e.g., `memcached -p 11211`');\n});\n","lang":"typescript","description":"Demonstrates initializing `express-rate-limit` with `rate-limit-memcached` for distributed rate limiting across an Express application, using environment variables for Memcached host.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}