{"id":18062803,"url":"https://github.com/ded/express-limiter","last_synced_at":"2025-05-16T13:02:52.813Z","repository":{"id":15306341,"uuid":"18036201","full_name":"ded/express-limiter","owner":"ded","description":"Rate limiting middleware for Express","archived":false,"fork":false,"pushed_at":"2019-04-12T23:41:10.000Z","size":32,"stargazers_count":422,"open_issues_count":21,"forks_count":54,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-06T01:02:47.296Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ded.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-23T15:24:39.000Z","updated_at":"2025-03-18T08:35:50.000Z","dependencies_parsed_at":"2022-09-26T16:21:16.883Z","dependency_job_id":null,"html_url":"https://github.com/ded/express-limiter","commit_stats":null,"previous_names":["ded/rate-limitter"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ded%2Fexpress-limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ded%2Fexpress-limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ded%2Fexpress-limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ded%2Fexpress-limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ded","download_url":"https://codeload.github.com/ded/express-limiter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254224485,"owners_count":22035240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-31T05:08:28.785Z","updated_at":"2025-05-16T13:02:52.795Z","avatar_url":"https://github.com/ded.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Express rate-limiter\nRate limiting middleware for Express applications built on redis\n\n``` sh\nnpm install express-limiter --save\n```\n\n``` js\nvar express = require('express')\nvar app = express()\nvar client = require('redis').createClient()\n\nvar limiter = require('express-limiter')(app, client)\n\n/**\n * you may also pass it an Express 4.0 `Router`\n *\n * router = express.Router()\n * limiter = require('express-limiter')(router, client)\n */\n\nlimiter({\n  path: '/api/action',\n  method: 'get',\n  lookup: ['connection.remoteAddress'],\n  // 150 requests per hour\n  total: 150,\n  expire: 1000 * 60 * 60\n})\n\napp.get('/api/action', function (req, res) {\n  res.send(200, 'ok')\n})\n```\n\n### API options\n\n``` js\nlimiter(options)\n```\n\n - `path`: `String` *optional* route path to the request\n - `method`: `String` *optional* http method. accepts `get`, `post`, `put`, `delete`, and of course Express' `all`\n - `lookup`: `Function|String|Array.\u003cString\u003e` value lookup on the request object. Can be a single value, array or function. See [examples](#examples) for common usages\n - `total`: `Number` allowed number of requests before getting rate limited\n - `expire`: `Number` amount of time in `ms` before the rate-limited is reset\n - `whitelist`: `function(req)` optional param allowing the ability to whitelist. return `boolean`, `true` to whitelist, `false` to passthru to limiter.\n - `skipHeaders`: `Boolean` whether to skip sending HTTP headers for rate limits ()\n - `ignoreErrors`: `Boolean` whether errors generated from redis should allow the middleware to call next().  Defaults to false.\n - `onRateLimited`: `Function` called when a request exceeds the configured rate limit.\n\n### Examples\n\n``` js\n// limit by IP address\nlimiter({\n  ...\n  lookup: 'connection.remoteAddress'\n  ...\n})\n\n// or if you are behind a trusted proxy (like nginx)\nlimiter({\n  lookup: 'headers.x-forwarded-for'\n})\n\n// by user (assuming a user is logged in with a valid id)\nlimiter({\n  lookup: 'user.id'\n})\n\n// limit your entire app\nlimiter({\n  path: '*',\n  method: 'all',\n  lookup: 'connection.remoteAddress'\n})\n\n// limit users on same IP\nlimiter({\n  path: '*',\n  method: 'all',\n  lookup: ['user.id', 'connection.remoteAddress']\n})\n\n// whitelist user admins\nlimiter({\n  path: '/delete/thing',\n  method: 'post',\n  lookup: 'user.id',\n  whitelist: function (req) {\n    return !!req.user.is_admin\n  }\n})\n\n// skip sending HTTP limit headers\nlimiter({\n  path: '/delete/thing',\n  method: 'post',\n  lookup: 'user.id',\n  whitelist: function (req) {\n    return !!req.user.is_admin\n  },\n  skipHeaders: true\n})\n\n// call a custom limit handler\nlimiter({\n  path: '*',\n  method: 'all',\n  lookup: 'connection.remoteAddress',\n  onRateLimited: function (req, res, next) {\n    next({ message: 'Rate limit exceeded', status: 429 })\n  }\n})\n\n// with a function for dynamic-ness\nlimiter({\n  lookup: function(req, res, opts, next) {\n    if (validApiKey(req.query.api_key)) {\n      opts.lookup = 'query.api_key'\n      opts.total = 100\n    } else {\n      opts.lookup = 'connection.remoteAddress'\n      opts.total = 10\n    }\n    return next()\n  }\n})\n\n```\n\n### as direct middleware\n\n``` js\napp.post('/user/update', limiter({ lookup: 'user.id' }), function (req, res) {\n  User.find(req.user.id).update(function (err) {\n    if (err) next(err)\n    else res.send('ok')\n  })\n})\n```\n\n## License MIT\n\nHappy Rate Limiting!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fded%2Fexpress-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fded%2Fexpress-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fded%2Fexpress-limiter/lists"}