{"_id":"@canmertinyo/rate-limiter-memcached","_rev":"4-aa8ead769dcf926b6c36f0c2f45937b3","name":"@canmertinyo/rate-limiter-memcached","dist-tags":{"latest":"2.1.9"},"versions":{"2.1.4":{"name":"@canmertinyo/rate-limiter-memcached","version":"2.1.4","keywords":["rate-limiter","express","middleware","redis","mongodb","in-memory","rate-limit-express","api-rate-limiting","express-middleware","nodejs"],"author":{"name":"c4nzin"},"license":"MIT","_id":"@canmertinyo/rate-limiter-memcached@2.1.4","maintainers":[{"name":"canmertinyo","email":"squalcan@gmail.com"}],"homepage":"https://github.com/c4nzin/rate-limiter-express#readme","bugs":{"url":"https://github.com/c4nzin/rate-limiter-express/issues"},"dist":{"shasum":"0d4e447841754fcf5afffc66a5ebeb82fdebef2c","tarball":"https://registry.npmjs.org/@canmertinyo/rate-limiter-memcached/-/rate-limiter-memcached-2.1.4.tgz","fileCount":9,"integrity":"sha512-/PIjie1jGm+cDkDY++ado58CGus5a/xICAScs3iwLkO9pba6WkX57Rcbcp7od5Zb2awgaNs4kqpLD4GZ1EBqOg==","signatures":[{"sig":"MEUCIQCnNCU3zs5axCvqScDRBp48xXU0EZtJC9lPK0mJOzuovgIgeYE8HDqxNpg7qyoEVm0RcekPJ3VKKlMHtLZAXkwrpXM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":17195},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"72d0163e4d23b2dd822464f610b950f58e571fe4","scripts":{"build":"tsc","publish":"npm publish"},"_npmUser":{"name":"canmertinyo","email":"squalcan@gmail.com"},"repository":{"url":"git+https://github.com/c4nzin/rate-limiter-express.git","type":"git"},"_npmVersion":"10.9.0","description":"A simple rate-limiting middleware for Express.js with support for in-memory, Redis, and MongoDB storage","directories":{},"_nodeVersion":"22.11.0","dependencies":{"memcached":"^2.2.2","@types/memcached":"^2.2.10","@canmertinyo/rate-limiter-core":"^1.3.9"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.7.2","@types/express":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/rate-limiter-memcached_2.1.4_1733211421623_0.7539705392964389","host":"s3://npm-registry-packages"}},"2.1.6":{"name":"@canmertinyo/rate-limiter-memcached","version":"2.1.6","keywords":["rate-limiter","express","middleware","redis","mongodb","in-memory","rate-limit-express","api-rate-limiting","express-middleware","nodejs"],"author":{"name":"c4nzin"},"license":"MIT","_id":"@canmertinyo/rate-limiter-memcached@2.1.6","maintainers":[{"name":"canmertinyo","email":"squalcan@gmail.com"}],"homepage":"https://github.com/c4nzin/rate-limiter-express#readme","bugs":{"url":"https://github.com/c4nzin/rate-limiter-express/issues"},"dist":{"shasum":"237b0f196d68be5d53c8235b42c5e4bbcf23b0e6","tarball":"https://registry.npmjs.org/@canmertinyo/rate-limiter-memcached/-/rate-limiter-memcached-2.1.6.tgz","fileCount":9,"integrity":"sha512-cLteDYRz2bqbvAI+iiQzvdvgxCpDw4H1+keEYO8LIuY4mNMYfMiryxH7mr2hxHRi5Z46nWcGD9KbqcKffkQl4Q==","signatures":[{"sig":"MEYCIQC08ZOAWXAjN4H7Mqij6OUqBBfEVxh2mZC8iiFIolO39QIhAItlBOgOqmrTzz9SKzpdwhYz5PuvQtAr4SUDSSrEHBjQ","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":18000},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"72d0163e4d23b2dd822464f610b950f58e571fe4","scripts":{"build":"tsc","publish":"npm publish"},"_npmUser":{"name":"canmertinyo","email":"squalcan@gmail.com"},"repository":{"url":"git+https://github.com/c4nzin/rate-limiter-express.git","type":"git"},"_npmVersion":"10.9.0","description":"A simple rate-limiting middleware for Express.js with support for in-memory, Redis, and MongoDB storage","directories":{},"_nodeVersion":"22.11.0","dependencies":{"memcached":"^2.2.2","@types/memcached":"^2.2.10","@canmertinyo/rate-limiter-core":"^1.3.9"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.7.2","@types/express":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/rate-limiter-memcached_2.1.6_1733213002031_0.2554809814897723","host":"s3://npm-registry-packages"}},"2.1.7":{"name":"@canmertinyo/rate-limiter-memcached","version":"2.1.7","keywords":["rate-limiter","express","middleware","redis","mongodb","in-memory","rate-limit-express","api-rate-limiting","express-middleware","nodejs"],"author":{"name":"c4nzin"},"license":"MIT","_id":"@canmertinyo/rate-limiter-memcached@2.1.7","maintainers":[{"name":"canmertinyo","email":"squalcan@gmail.com"}],"homepage":"https://github.com/c4nzin/rate-limiter-express#readme","bugs":{"url":"https://github.com/c4nzin/rate-limiter-express/issues"},"dist":{"shasum":"6eea4aefecf4e40c396231c348d7966e552fa951","tarball":"https://registry.npmjs.org/@canmertinyo/rate-limiter-memcached/-/rate-limiter-memcached-2.1.7.tgz","fileCount":9,"integrity":"sha512-v6JclsksqyE0Dp07E/RkbOdqxOviFZuyqCs7KnvvZptN1ZXLy6AQKZ2qQLwGaDgbd0k7f6gZqvL88QQA1Ao4xQ==","signatures":[{"sig":"MEYCIQD9ixXqXUlGOsPbVWdLtTMhbmvSWFQ02g78TWbDGd3qOAIhAP+qI12emR96FV11ilMw/K0X3GLsxXzg3DS2k6KWWm0l","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":17583},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"72d0163e4d23b2dd822464f610b950f58e571fe4","scripts":{"build":"tsc","publish":"npm publish"},"_npmUser":{"name":"canmertinyo","email":"squalcan@gmail.com"},"repository":{"url":"git+https://github.com/c4nzin/rate-limiter-express.git","type":"git"},"_npmVersion":"10.9.0","description":"A simple rate-limiting middleware for Express.js with support for in-memory, Redis, and MongoDB storage","directories":{},"_nodeVersion":"22.11.0","dependencies":{"memcached":"^2.2.2","@types/memcached":"^2.2.10","@canmertinyo/rate-limiter-core":"^1.3.9"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.7.2","@types/express":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/rate-limiter-memcached_2.1.7_1733213407181_0.5421287201450242","host":"s3://npm-registry-packages"}},"2.1.8":{"name":"@canmertinyo/rate-limiter-memcached","version":"2.1.8","keywords":["rate-limiter","express","middleware","redis","mongodb","in-memory","rate-limit-express","api-rate-limiting","express-middleware","nodejs"],"author":{"name":"c4nzin"},"license":"MIT","_id":"@canmertinyo/rate-limiter-memcached@2.1.8","maintainers":[{"name":"canmertinyo","email":"squalcan@gmail.com"}],"homepage":"https://github.com/c4nzin/rate-limiter-express#readme","bugs":{"url":"https://github.com/c4nzin/rate-limiter-express/issues"},"dist":{"shasum":"7c07a0ddc810faf6a641f87fb0324ca5cbf366cd","tarball":"https://registry.npmjs.org/@canmertinyo/rate-limiter-memcached/-/rate-limiter-memcached-2.1.8.tgz","fileCount":9,"integrity":"sha512-hd3zq6T1DNo83BxFCVg36gfzA5hrb2xtRsQxxpTDbtxSQcvLCfAf6GrLG/ZXzHXwUBmVtRR9yrvVqMrGputC9w==","signatures":[{"sig":"MEYCIQCcAsiD+vd5sTnkG4GJs4AelW58ovxgDogW6fA3KCSQPwIhAIkqDKp4PV/2Rx4EODpEFPgrg/pdc6saUwQ7IdtmUZkz","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":18482},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"7cb552657bac82c073159987b05422c6586ff384","scripts":{"build":"tsc","publish":"npm publish"},"_npmUser":{"name":"canmertinyo","email":"squalcan@gmail.com"},"repository":{"url":"git+https://github.com/c4nzin/rate-limiter-express.git","type":"git"},"_npmVersion":"10.9.0","description":"A simple rate-limiting middleware for Express.js with support for in-memory, Redis, and MongoDB storage","directories":{},"_nodeVersion":"22.11.0","dependencies":{"memcached":"^2.2.2","@types/memcached":"^2.2.10","@canmertinyo/rate-limiter-core":"^1.3.9"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.7.2","@types/express":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/rate-limiter-memcached_2.1.8_1733213926260_0.6633110569072451","host":"s3://npm-registry-packages"}},"2.1.9":{"name":"@canmertinyo/rate-limiter-memcached","description":"A simple rate-limiting middleware for Express.js with support for in-memory, Redis, and MongoDB storage","version":"2.1.9","main":"dist/index.js","license":"MIT","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/c4nzin/rate-limiter-express.git"},"scripts":{"build":"tsc","publish":"npm publish"},"keywords":["rate-limiter","express","middleware","redis","mongodb","in-memory","rate-limit-express","api-rate-limiting","express-middleware","nodejs"],"author":{"name":"c4nzin"},"devDependencies":{"@types/express":"^5.0.0","typescript":"^5.7.2"},"dependencies":{"@canmertinyo/rate-limiter-core":"^1.3.9","@types/memcached":"^2.2.10","memcached":"^2.2.2"},"publishConfig":{"access":"public"},"_id":"@canmertinyo/rate-limiter-memcached@2.1.9","gitHead":"57c3117e4ea16518f62429ef3e41a0628ef19258","bugs":{"url":"https://github.com/c4nzin/rate-limiter-express/issues"},"homepage":"https://github.com/c4nzin/rate-limiter-express#readme","_nodeVersion":"22.11.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-nr3J33DEzVWwLMRAr6LwfrisAVaxDopiDYre4omcWwG0nTRF+BZFWcWZybeTLODMmIJ5qjqi5dWcVAasjcQ7/g==","shasum":"245ae85df927f6081f3465912f4ed861638442da","tarball":"https://registry.npmjs.org/@canmertinyo/rate-limiter-memcached/-/rate-limiter-memcached-2.1.9.tgz","fileCount":9,"unpackedSize":18673,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIA3ss64ZcbyzEJxI38suK/3s3LHayaCpp6Pes8+Ep7/vAiA/B53nC59cpr6dDIUjV+sTZS4L9B/eWhzQ4hHUPByVWA=="}]},"_npmUser":{"name":"canmertinyo","email":"squalcan@gmail.com"},"directories":{},"maintainers":[{"name":"canmertinyo","email":"squalcan@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rate-limiter-memcached_2.1.9_1733214528187_0.19240539317710192"},"_hasShrinkwrap":false}},"time":{"created":"2024-12-03T07:37:01.449Z","modified":"2024-12-03T08:28:48.540Z","2.1.4":"2024-12-03T07:37:01.837Z","2.1.6":"2024-12-03T08:03:22.199Z","2.1.7":"2024-12-03T08:10:07.353Z","2.1.8":"2024-12-03T08:18:46.417Z","2.1.9":"2024-12-03T08:28:48.342Z"},"bugs":{"url":"https://github.com/c4nzin/rate-limiter-express/issues"},"author":{"name":"c4nzin"},"license":"MIT","homepage":"https://github.com/c4nzin/rate-limiter-express#readme","keywords":["rate-limiter","express","middleware","redis","mongodb","in-memory","rate-limit-express","api-rate-limiting","express-middleware","nodejs"],"repository":{"type":"git","url":"git+https://github.com/c4nzin/rate-limiter-express.git"},"description":"A simple rate-limiting middleware for Express.js with support for in-memory, Redis, and MongoDB storage","maintainers":[{"name":"canmertinyo","email":"squalcan@gmail.com"}],"readme":"# Express Rate Limiter\r\n\r\n### This set of packages provides flexible and highly customizable rate-limiting solutions for Node.js applications. The core package, @canmertinyo/rate-limiter-core, includes the in-memory implementation. To enable storage-backed rate limiting, you can integrate it with either @canmertinyo/rate-limiter-mongo for MongoDB, @canmertinyo/rate-limiter-redis for Redis, or @canmertinyo/rate-limiter-memcached for Memcached.\r\n\r\n## Rate Limiter Options\r\n\r\n| **Option**         | **Type**   | **Description**                                                                           | **Default Value**        | **Example**                                             |\r\n| ------------------ | ---------- | ----------------------------------------------------------------------------------------- | ------------------------ | ------------------------------------------------------- |\r\n| `ms`               | `number`   | Time window in milliseconds for rate limiting.                                            | `60000` (1 minute)       | `ms: 60000`                                             |\r\n| `maxRequest`       | `number`   | Maximum requests allowed within the time window.                                          | `10`                     | `maxRequest: 10`                                        |\r\n| `storage`          | `object`   | Storage manager for rate limits (e.g., in-memory, MongoDB, Redis, Memcached).             | `undefined` (in-memory)  | `storage: mongoStorage`                                 |\r\n| `message`          | `string`   | Custom message returned when rate limit is exceeded.                                      | `\"Too many requests\"`    | `message: \"Too many requests, please try again later.\"` |\r\n| `statusCode`       | `number`   | HTTP status code for rate limit responses.                                                | `429`                    | `statusCode: 429`                                       |\r\n| `keyGenerator`     | `function` | Function to generate a unique key for rate limiting (e.g., based on `req.ip` or headers). | `(req) => req.ip`        | `keyGenerator: (req) => req.ip`                         |\r\n| `skip`             | `function` | Function to bypass rate limiting for certain requests (e.g., based on user role).         | `undefined`              | `skip: (req) => req.headers[\"x-user-role\"] === \"admin\"` |\r\n| `errorHandler`     | `function` | Error handling function for issues from the storage layer.                                | Logs error and proceeds. | `errorHandler: (req, res, next) => next()`              |\r\n| `passOnStoreError` | `boolean`  | Whether to allow requests to pass even if the storage fails.                              | `false`                  | `passOnStoreError: true`                                |\r\n\r\nTo install (Core version only in memory):\r\n\r\n```bash\r\nnpm install @canmertinyo/rate-limiter-core\r\n```\r\n\r\nTo install (Mongo store):\r\n\r\n```bash\r\nnpm install @canmertinyo/rate-limiter-mongo mongoose\r\n```\r\n\r\nTo install (Redis store)\r\n\r\n```bash\r\nnpm install @canmertinyo/rate-limiter-redis ioredis\r\n```\r\n\r\nTo install (Memcached store)\r\n\r\n```bash\r\nnpm install @canmertinyo/rate-limiter-memcached memcached\r\n```\r\n\r\n# Example usage :\r\n\r\n```typescript\r\nimport express from \"express\";\r\nimport { rateLimiter } from \"@canmertinyo/rate-limiter-core\";\r\n\r\nconst app = express();\r\n\r\n// Apply rate limiter middleware\r\napp.use(\r\n  rateLimiter({\r\n    ms: 60000, // Time in milliseconds\r\n    maxRequest: 5, // Maximum requests allowed within the time\r\n    //DEFAULT IS IN MEMORY\r\n  })\r\n);\r\n\r\napp.get(\"/\", (req, res) => {\r\n  res.send(\"Welcome to the API!\");\r\n});\r\n\r\napp.listen(3000, () => {\r\n  console.log(\"Server is running on http://localhost:3000\");\r\n});\r\n```\r\n\r\n# Using Redis As A Store Manager\r\n\r\n```typescript\r\nimport express from \"express\";\r\nimport { RedisStorage } from \"@canmertinyo/rate-limiter-redis\";\r\nimport { rateLimiter } from \"@canmertinyo/rate-limiter-core\";\r\n\r\nconst app = express();\r\nconst port = 3001;\r\n\r\n// Configure the rate limiter with Redis storage\r\napp.use(\r\n  rateLimiter({\r\n    ms: 5000, // Time window in milliseconds\r\n    maxRequest: 2, // Maximum requests allowed in the time window\r\n    storage: new RedisStorage({ host: \"127.0.0.1\", port: 6379 }), // Redis configuration\r\n  })\r\n);\r\n\r\n// Sample route\r\napp.get(\"/\", (req, res) => {\r\n  res.send(\"Hello World!\");\r\n});\r\n\r\n// Start the server\r\napp.listen(port, () => {\r\n  console.log(`Server listening on port ${port}`);\r\n});\r\n```\r\n\r\n# Using Mongo As A Store Manager\r\n\r\n```typescript\r\nimport express from \"express\";\r\nimport { MongoStorage } from \"@canmertinyo/rate-limiter-mongo\";\r\nimport { rateLimiter } from \"@canmertinyo/rate-limiter-core\";\r\n\r\nconst app = express();\r\nconst port = 3001;\r\n\r\n// MongoDB connection string (replace with your MongoDB URL)\r\nconst mongoUrl = \"mongodb://your-mongodb-url\";\r\n\r\napp.use(\r\n  rateLimiter({\r\n    ms: 5000, // Time window in milliseconds\r\n    maxRequest: 2, // Maximum requests allowed in the time window\r\n    storage: new MongoStorage(mongoUrl), // MongoDB configuration\r\n  })\r\n);\r\n\r\n// Sample route\r\napp.get(\"/\", (req, res) => {\r\n  res.send(\"Hello World!\");\r\n});\r\n\r\n// Start the server\r\napp.listen(port, () => {\r\n  console.log(`Server listening on port ${port}`);\r\n});\r\n```\r\n\r\n```typescript\r\napp.use(\r\n  rateLimiter({\r\n    ms: 60000, // Time window in milliseconds\r\n    maxRequest: 10, // Maximum requests allowed\r\n    storage: mongoStorage, // Use MongoDB or Redis as storage or just leave it as empty. it will behave in memory storage\r\n    message: \"Too many requests, please try again later.\", // Custom rate limit message\r\n    statusCode: 429, // OPTIONAL: You can fully optimize HTTP status code for rate limit response\r\n    keyGenerator: (req) => req.ip, //OPTIONAL :  Custom key generator\r\n    skip: (req) => {\r\n      //OPTIONAL :\r\n      const userRole = req.headers[\"x-user-role\"]; // Assume user role is passed in headers\r\n      return userRole === \"admin\"; // Skip rate limiting for admin users\r\n    },\r\n    errorHandler: (req, res, next) => {\r\n      console.error(\"Rate limiter error\");\r\n      next();\r\n    }, // Handle errors from storage\r\n    passOnStoreError: true, // Pass requests even if storage fails\r\n  })\r\n);\r\n```\r\n\r\n# Using memcached as a store manager\r\n\r\n```typescript\r\nimport express from \"express\";\r\nimport { MemcachedStore } from \"@canmertinyo/rate-limiter-memcached\";\r\nimport { rateLimiter } from \"@canmertinyo/rate-limiter-core\";\r\n\r\nconst app = express();\r\nconst port = 3001;\r\n\r\n// Configure the rate limiter with Memcached storage\r\napp.use(\r\n  rateLimiter({\r\n    ms: 5000, // Time window in milliseconds\r\n    maxRequest: 2, // Maximum requests allowed in the time window\r\n    storage: new MemcachedStore(\"127.0.0.1:11211\", { //optons for customize db behaivor }), // Memcached configuration\r\n  })\r\n);\r\n\r\n// Sample route\r\napp.get(\"/\", (req, res) => {\r\n  res.send(\"Hello World!\");\r\n});\r\n\r\n// Start the server\r\napp.listen(port, () => {\r\n  console.log(`Server listening on port ${port}`);\r\n});\r\n\r\n```\r\n","readmeFilename":"README.md"}