{"id":19782109,"url":"https://github.com/express-rate-limit/rate-limit-postgresql","last_synced_at":"2025-04-30T22:30:39.808Z","repository":{"id":194517373,"uuid":"688829713","full_name":"express-rate-limit/rate-limit-postgresql","owner":"express-rate-limit","description":"A PostgreSQL store for express-rate-limit middleware","archived":false,"fork":false,"pushed_at":"2025-04-01T06:31:01.000Z","size":811,"stargazers_count":12,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-23T11:02:05.200Z","etag":null,"topics":["express-middleware","nodejs","postgresql","rate-limiting","security"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@acpr/rate-limit-postgresql","language":"PLpgSQL","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/express-rate-limit.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":"contributing.md","funding":null,"license":"license.md","code_of_conduct":"code_of_conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-09-08T07:37:08.000Z","updated_at":"2025-04-01T06:30:58.000Z","dependencies_parsed_at":"2023-09-13T19:31:08.100Z","dependency_job_id":"63c4da80-6ab2-42ec-834c-cc568b34a64a","html_url":"https://github.com/express-rate-limit/rate-limit-postgresql","commit_stats":null,"previous_names":["adrianprelipcean/express-rate-limit-postgresql","express-rate-limit/rate-limit-postgresql"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/express-rate-limit%2Frate-limit-postgresql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/express-rate-limit%2Frate-limit-postgresql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/express-rate-limit%2Frate-limit-postgresql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/express-rate-limit%2Frate-limit-postgresql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/express-rate-limit","download_url":"https://codeload.github.com/express-rate-limit/rate-limit-postgresql/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251791438,"owners_count":21644396,"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":["express-middleware","nodejs","postgresql","rate-limiting","security"],"created_at":"2024-11-12T06:03:50.363Z","updated_at":"2025-04-30T22:30:39.483Z","avatar_url":"https://github.com/express-rate-limit.png","language":"PLpgSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rate-limit-postgresql\n\n[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)\n\nA [`PostgreSQL`](https://www.postgresql.org/) store for the\n[`express-rate-limit`](https://github.com/nfriedly/express-rate-limit)\nmiddleware.\n\n## Installation\n\nFrom the npm registry:\n\n```sh\n# Using npm\n\u003e npm install --save @acpr/rate-limit-postgresql\n# Using yarn or pnpm\n\u003e yarn/pnpm add @acpr/rate-limit-postgresql\n```\n\n## Usage\n\nFunctional examples for using `rate-limit-postgresql` are found in the\n[following repository](https://github.com/adrianprelipcean/express-rate-limit-postgresql-examples)\n\n```js\nlet rateLimit = require('express-rate-limit')\nlet postgresStores = require('@acpr/rate-limit-postgresql')\n\nlet limiter = new RateLimit({\n\tstore: new postgresStores.PostgresStore(\n\t\t{\n\t\t\tuser: 'postgres',\n\t\t\tpassword: 'postgres',\n\t\t\thost: 'localhost',\n\t\t\tdatabase: 'rate-limit',\n\t\t\tport: 5432,\n\t\t},\n\t\t'aggregated_store',\n\t),\n\twindowMs: 15 * 60 * 1000, // 15 minutes\n\tmax: 3, // Limit each IP to 3 requests per `window` (here, per 15 minutes)\n\tmessage:\n\t\t'Too many accounts created from this IP, please try again after 15 minutes',\n\tstandardHeaders: 'draft-7', // Set `RateLimit` and `RateLimit-Policy`` headers\n\tlegacyHeaders: false,\n})\n\n//  apply to all requests\napp.use(limiter)\n```\n\n### Importing\n\nThis library is provided in ESM as well as CJS forms, and works with both\nJavascript and Typescript projects.\n\n**This package requires you to use Node 16 or above.**\n\nImport it in a CommonJS project (`type: commonjs` or no `type` field in\n`package.json`) as follows:\n\n```ts\nlet postgresStores = require('@acpr/rate-limit-postgresql')\n```\n\nImport it in a ESM project (`type: module` in `package.json`) as follows:\n\n```ts\nimport postgresStores from '@acpr/rate-limit-postgresql'\n```\n\n## Configuration\n\n### Types of Postgres Stores\n\nThere are two different types of Postgres Stores:\n\n1. `PostgresStoreAggregatedIP` (with the default `PostgresStore` constructor)-\n   which aggregates the IP count in the table, as shown in the following table\n\n| key         | session_id | count |\n| ----------- | ---------- | ----- |\n| 192.168.1.1 | 1          | 3     |\n| 192.168.2.1 | 1          | 1     |\n\n2. `PostgresStoreIndividualIP` - which stores the IP of each request in a\n   separate row (as shown in the following table) and performs the aggregation\n   at a separate step\n\n| id  | key         | session_id | event_time                |\n| --- | ----------- | ---------- | ------------------------- |\n| 1   | 192.168.1.1 | 1          | 2023-09-13T07:40:09+00:00 |\n| 2   | 192.168.1.1 | 1          | 2023-09-13T07:40:10+00:00 |\n| 3   | 192.168.1.1 | 1          | 2023-09-13T07:40:11+00:00 |\n| 4   | 192.168.2.1 | 1          | 2023-09-13T07:40:11+00:00 |\n\n\u003e Note: The database uses UUID as a data type for IDs, the tables contain\n\u003e integers as IDs to keep illustration simple.\n\n### Constructor\n\nBoth types of store take the same input in their constructor\n\n- `config` - The database configuration as specified in the\n  [node-postgres](https://node-postgres.com/apis/client) configuration.\n- `prefix` - The unique name of the session (persisted in the database). Used by\n  the double-count check to avoid false-positives when a key is counted twice,\n  but with different prefixes.\n\n## Installation\n\nProject license is specified in the [license file](license.md). Third party\nlicenses are located in the [third_party_licenses folder](third_party_licenses)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpress-rate-limit%2Frate-limit-postgresql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpress-rate-limit%2Frate-limit-postgresql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpress-rate-limit%2Frate-limit-postgresql/lists"}