{"id":18480,"library":"koa2-ratelimit","title":"koa2-ratelimit","description":"IP rate-limiting middleware for Koa2, inspired by express-rate-limit. Version 1.1.3 supports Redis, MongoDB (via Mongoose), and Sequelize stores. Release cadence is low; last significant update was in 2020. Differentiators: async/await, flexible interval config (ms or object), per-route keys, and delay-after behavior for throttling. Requires Node >=7.10 and peer deps for advanced stores.","status":"active","version":"1.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/ysocorp/koa2-ratelimit","tags":["javascript","koa2-ratelimit","koa2-rate-limit","koa-rate-limit","koa-ratelimit","koa2-brute-force","koa-brute-force","koa2-bruteforce"],"install":[{"cmd":"npm install koa2-ratelimit","lang":"bash","label":"npm"},{"cmd":"yarn add koa2-ratelimit","lang":"bash","label":"yarn"},{"cmd":"pnpm add koa2-ratelimit","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for MongoDB store (optional peer dep)","package":"mongoose","optional":true},{"reason":"Required for Redis store (optional peer dep, v4+)","package":"redis","optional":true},{"reason":"Required for Sequelize store (optional peer dep)","package":"sequelize","optional":true}],"imports":[{"note":"Package is CJS-only; ESM import may cause errors unless using bundler.","wrong":"import { RateLimit } from 'koa2-ratelimit';","symbol":"RateLimit","correct":"const { RateLimit } = require('koa2-ratelimit');"},{"note":"Both patterns work, but destructuring is cleaner.","wrong":"const Stores = require('koa2-ratelimit').Stores;","symbol":"Stores","correct":"const { Stores } = require('koa2-ratelimit');"},{"note":"No default export; always use named exports.","wrong":"import koa2Ratelimit from 'koa2-ratelimit';","symbol":"default","correct":"const koa2Ratelimit = require('koa2-ratelimit');"}],"quickstart":{"code":"const Koa = require('koa');\nconst { RateLimit } = require('koa2-ratelimit');\n\nconst app = new Koa();\n\nconst limiter = RateLimit.middleware({\n  interval: { min: 15 },\n  max: 100,\n  message: 'Too many requests, please try again later.'\n});\n\napp.use(limiter);\n\napp.use(async (ctx) => {\n  ctx.body = 'Hello World';\n});\n\napp.listen(3000);","lang":"javascript","description":"Basic Koa2 app with rate limiting: 100 requests per 15 minutes per IP."},"warnings":[{"fix":"Update to v1.0.0+ and remove `messageKey` from options. Override `message` as a function to customize response.","message":"In v1.0.0, the `messageKey` option was removed; responses now use a standard JSON format.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Add `prefixKey` to your middleware options, e.g., `prefixKey: 'my-route'`.","message":"In v1.0.0, `prefixKey` is now required when using stores to differentiate endpoints.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Remove `delayAfter` and `timeWait`; use rate-only limiting.","message":"The `delayAfter` and `timeWait` options are deprecated in favor of simpler throttling mechanisms.","severity":"deprecated","affected_versions":">=0.9.0"},{"fix":"Install `npm install redis@4` and update client configuration to v4 style.","message":"Redis store requires `redis@4`; older `redis@2` or `redis@3` will cause connection errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install `@types/koa2-ratelimit` or declare module manually.","message":"The package does not ship TypeScript definitions; you must create your own or use `@types/koa2-ratelimit` (community).","severity":"gotcha","affected_versions":">=0.9.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install redis@4` in your project.","cause":"Redis store used but 'redis' package not installed.","error":"Error: Cannot find module 'redis'"},{"fix":"Use number (milliseconds) or object like `{ hour: 1 }`. See docs for supported units.","cause":"Interval provided in unsupported format (e.g., string).","error":"TypeError: Invalid interval: must be a number or an object with time units"},{"fix":"Use `RateLimit.middleware(options)` only once.","cause":"Using `RateLimit.middleware.middleware()` (typo in README).","error":"TypeError: Cannot read property 'middleware' of undefined"},{"fix":"Add `prefixKey: 'someKey'` to middleware options.","cause":"Using a database store without specifying `prefixKey`.","error":"Error: prefixKey is required when using a store"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}