{"id":14978176,"url":"https://github.com/yatki/flood-protection","last_synced_at":"2025-10-28T08:31:54.019Z","repository":{"id":57238613,"uuid":"108323273","full_name":"yatki/flood-protection","owner":"yatki","description":"Flood protection for realtime applications","archived":false,"fork":false,"pushed_at":"2020-08-20T21:21:39.000Z","size":115,"stargazers_count":18,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T13:02:12.422Z","etag":null,"topics":["anti-spam","chat","flood-protection","message-rate-limiting","rate","rate-limiting","realtime","socket-io","spam-protection"],"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/yatki.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":"2017-10-25T20:36:31.000Z","updated_at":"2023-08-30T11:20:02.000Z","dependencies_parsed_at":"2022-08-26T15:11:59.307Z","dependency_job_id":null,"html_url":"https://github.com/yatki/flood-protection","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yatki%2Fflood-protection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yatki%2Fflood-protection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yatki%2Fflood-protection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yatki%2Fflood-protection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yatki","download_url":"https://codeload.github.com/yatki/flood-protection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238623150,"owners_count":19502990,"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":["anti-spam","chat","flood-protection","message-rate-limiting","rate","rate-limiting","realtime","socket-io","spam-protection"],"created_at":"2024-09-24T13:56:59.682Z","updated_at":"2025-10-28T08:31:48.624Z","avatar_url":"https://github.com/yatki.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flood-protection\n\u003e Flood protection for realtime applications\n\n[![NPM version](https://badge.fury.io/js/flood-protection.svg)](https://www.npmjs.com/package/flood-protection)\n[![Build Status](https://travis-ci.org/yatki/flood-protection.svg?branch=master)](https://travis-ci.org/yatki/flood-protection)\n[![Coverage Status](https://coveralls.io/repos/github/yatki/flood-protection/badge.svg?branch=master\u0026)](https://coveralls.io/github/yatki/flood-protection?branch=master)\n\n## Why?\n\nPurpose of this library is to have control on receiving data packages. \nIt allows you to **drop** data packages (e.g. messages) if they arrive **too quickly**.\nAs an example you may want to use it *to prevent spam messages in chat rooms* or *to limit number of requests to your http/express server*.\n\n### Notes:\n\n- I basically rewrote the python solution which was stated here for my own needs in javascript: [https://stackoverflow.com/a/668327/1417536](https://stackoverflow.com/a/668327/1417536).\n- This library uses [Token Bucket Algorithm](https://en.wikipedia.org/wiki/Token_bucket). \n\n## Install\n\n```\nnpm install --save flood-protection\n```\n\n## Usage\n\n```javascript\nimport FloodProtection from 'flood-protection';\n\nconst floodProtection = new FloodProtection({\n    rate: 5, \n    // default: 5, unit: messages\n    // IMPORTANT: rate must be \u003e= 1 (greater than or equal to 1)\n    \n    per: 8, \n    // default: 8, unit: seconds\n  });\n```\n\n## Basic Example\n\n```javascript\nimport FloodProtection from 'flood-protection';\n\n// ...\n// io is a Socket.io instance...\n\nio.on('connection', (client) =\u003e {\n  client.emit('connected');\n\n  const floodProtection = new FloodProtection();\n \n  client.on('message', (text) =\u003e {\n    if (floodProtection.check()) {\n      // forward message\n      io.emit('message', text);     \n    } else {\n      // forbid message\n      client.emit('flood', {\n        text: 'Take it easy!',\n      });\n    }\n  });\n});\n```\n\n## Contribution\n\nAs always, I'm open to any contribution and would like to hear your feedback. \n\n### Just an important reminder:\n\nIf you are planning to contribute to **any** open source project, \nbefore starting development, please **always open an issue** and **make a proposal first**. \nThis will save you from working on features that are eventually going to be rejected for some reason.\n\n## LICENCE\n\nMIT (c) 2017 Mehmet Yatkı\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyatki%2Fflood-protection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyatki%2Fflood-protection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyatki%2Fflood-protection/lists"}