{"id":17712625,"url":"https://github.com/doesdev/pg-ears","last_synced_at":"2025-09-08T00:15:33.619Z","repository":{"id":57322562,"uuid":"84605309","full_name":"doesdev/pg-ears","owner":"doesdev","description":"Resilient Postgres listen client","archived":false,"fork":false,"pushed_at":"2020-01-18T23:36:08.000Z","size":69,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T11:41:16.959Z","etag":null,"topics":["listen","nodejs","npm-module","postgresql"],"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/doesdev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-03-10T22:17:53.000Z","updated_at":"2020-11-27T03:06:25.000Z","dependencies_parsed_at":"2022-08-26T01:11:25.424Z","dependency_job_id":null,"html_url":"https://github.com/doesdev/pg-ears","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doesdev%2Fpg-ears","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doesdev%2Fpg-ears/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doesdev%2Fpg-ears/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doesdev%2Fpg-ears/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doesdev","download_url":"https://codeload.github.com/doesdev/pg-ears/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249996105,"owners_count":21358064,"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":["listen","nodejs","npm-module","postgresql"],"created_at":"2024-10-25T09:05:52.776Z","updated_at":"2025-04-21T04:31:39.690Z","avatar_url":"https://github.com/doesdev.png","language":"JavaScript","readme":"# pg-ears [![NPM version](https://badge.fury.io/js/pg-ears.svg)](https://npmjs.org/package/pg-ears)   [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)   [![Dependency Status](https://dependencyci.com/github/doesdev/pg-ears/badge)](https://dependencyci.com/github/doesdev/pg-ears)\n\n\u003e Resilient Postgres listen client\n\n# Recommend using [pg-listen](https://github.com/andywer/pg-listen)\n\nThis project is not in any production use by the author. There has also been\nvery little community engagement on the module that would motivate the\nextensive time investment to make this module as good as `pg-listen`. Given\nthat module has more usage and is actively maintained I would strongly\nrecommend using that instead.\n\n## Known Issues\n\n- [LISTEN leaks](https://github.com/doesdev/pg-ears/issues/6):\nUpon disconnect and reconnect `LISTEN` statements accumulate\n\n## Install\n\n```sh\n$ npm install --save pg-ears\n```\n\n## API\n\npg-ears exports a single function takes the same options as a new\n`node-postgres` `new Client(opts)` with a couple additions and returns an object\ncontaining the methods `listen` and `notify`\n\n- **options** *(Object - required)* Options for [node-postgres](https://github.com/brianc/node-postgres) connection plus the\nfollowing:\n  - **checkInterval** *(Number (ms) - optional - default: 30000 [30 sec.])*\n  - **maxAttempts** *(Number - optional - default: 60)* Multiplier of\n  checkInterval - number of attempts before giving up on reconnect\n\n`listen(channel, callback)`\n- **channel** *(String - required)*\n- **callback** *(Function - required)* will be called every time a message is\nreceived with `(error, data)` as arguments OR with an error when the PG client\nencounters an error\n\n`notify(channel, payload, callback)`\n- **channel** *(Object - required)*\n- **payload** *(Object | Array | String - required)*\n- **callback** *(Object - optional)* will be called with error if unable to send\nOR when an error occurs on the PG client\n\n## Usage\n\n```js\nconst options = {\n  user: 'foo', //env var: PGUSER\n  database: 'my_db', //env var: PGDATABASE\n  password: 'secret', //env var: PGPASSWORD\n  host: 'localhost', // Server hosting the postgres database\n  port: 5432 //env var: PGPORT\n}\nconst pgEars = require('pg-ears')(options)\npgEars.listen('mychannel', (err, data) =\u003e {\n  if (err) return console.error(err)\n  console.log(data)\n})\npgEars.notify('mychannel', {key: 'value'}, (err) =\u003e {\n  if (err) console.error(err)\n})\n```\n\n## Use safe identifiers as channel names\n\n:warning: Channel names in postgresql are `identifiers`, just like the name of a\ntable or a column.\nPlease refer to the offical postgresql documentation about valid [identifiers](https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS).\n\nnode-postgres does not currently allows channel names to be parameterized to\navoid sql-injection attacks.\n\nSee node-postgres [issue #1258](https://github.com/brianc/node-postgres/issues/1258)\nfor details.\n\n**pg-ears performs no validation or sanitation on the channel names and they are\ninserted into the sql queries as-is.**\n\nOn the other hand, payloads of your notifications are json encoded and decoded\nautomatically by pg-ears and passed using safe parameterized queries.\n\n\n## License\n\nMIT © [Andrew Carpenter](https://github.com/doesdev)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoesdev%2Fpg-ears","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoesdev%2Fpg-ears","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoesdev%2Fpg-ears/lists"}