{"id":43549,"library":"pg-ears","title":"pg-ears","description":"Resilient Postgres LISTEN/NOTIFY client with automatic reconnection. Current stable version: 1.2.3. Low release cadence (no recent updates). The author recommends using pg-listen instead. Handles connection drops, but has known issue of accumulating LISTEN statements on reconnect. Differentiator: built-in reconnect with configurable check interval and max attempts.","status":"deprecated","version":"1.2.3","language":"javascript","source_language":"en","source_url":"https://github.com/doesdev/pg-ears","tags":["javascript","pg","postgres","listen","subscribe","notify"],"install":[{"cmd":"npm install pg-ears","lang":"bash","label":"npm"},{"cmd":"yarn add pg-ears","lang":"bash","label":"yarn"},{"cmd":"pnpm add pg-ears","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"node-postgres is required for database connection","package":"pg","optional":false}],"imports":[{"note":"CommonJS only; no ESM export. Must call the exported function with options.","wrong":"import pgEars from 'pg-ears'","symbol":"default (factory function)","correct":"const pgEars = require('pg-ears')(options)"},{"note":"Callback signature with error-first pattern; first argument is error, second is data.","wrong":"pgEars.listen('channel', data => {})","symbol":"listen","correct":"pgEars.listen('channel', (err, data) => {})"},{"note":"Optional callback; without callback, errors are silently lost.","wrong":"pgEars.notify('channel', payload)","symbol":"notify","correct":"pgEars.notify('channel', payload, (err) => {})"}],"quickstart":{"code":"const pgEars = require('pg-ears')({\n  user: process.env.PGUSER ?? '',\n  database: process.env.PGDATABASE ?? '',\n  password: process.env.PGPASSWORD ?? '',\n  host: process.env.PGHOST ?? 'localhost',\n  port: Number(process.env.PGPORT) || 5432\n})\npgEars.listen('mychannel', (err, data) => {\n  if (err) return console.error(err)\n  console.log(JSON.stringify(data))\n})\npgEars.notify('mychannel', {key: 'value'}, (err) => {\n  if (err) console.error(err)\n})","lang":"javascript","description":"Connect to Postgres, listen on a channel, and notify with JSON payload."},"warnings":[{"fix":"Switch to pg-listen (https://github.com/andywer/pg-listen)","message":"Author recommends using pg-listen instead of pg-ears","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Manually manage reconnection or switch to pg-listen","message":"LISTEN statements leak on reconnect; each reconnect adds another LISTEN without removing old ones","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure channel names are safe PostgreSQL identifiers; do not use user input directly","message":"Channel names are not sanitized; SQL injection possible if using dynamic channel names","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use require() instead of import","message":"No ESM export; module uses CommonJS only","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Always use (err, data) => {...} signature","message":"Callback for listen expects error-first (err, data); forgetting error argument causes silent failures","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'1.2.3':14 'accumul':37 'attempt':53 'author':22 'automat':9 'built':44 'built-in':43 'cadenc':17 'check':49 'client':7 'configur':48 'connect':30 'current':11 'differenti':42 'drop':31 'ear':3 'handl':29 'instead':28 'interv':50 'issu':35 'javascript':54 'known':34 'listen':27,38,57 'listen/notify':6 'low':15 'max':52 'notifi':59 'pg':2,26,55 'pg-ear':1 'pg-listen':25 'postgr':5,56 'recent':19 'recommend':23 'reconnect':10,41,46 'releas':16 'resili':4 'stabl':12 'statement':39 'subscrib':58 'updat':20 'use':24 'version':13","created_at":"2026-06-05T17:00:20.077740+00:00","updated_at":"2026-06-05T17:00:20.077740+00:00","problems":[{"fix":"Invoke the exported function: const pgEars = require('pg-ears')(options)","cause":"Calling require('pg-ears') instead of require('pg-ears')(options)","error":"TypeError: pgEars is not a function"},{"fix":"Avoid using pg-ears; use pg-listen instead","cause":"Reconnection causes duplicate LISTEN statements; known issue #6","error":"Error: listen statement accumulated"},{"fix":"npm install pg pg-ears","cause":"pg is a peer dependency not automatically installed","error":"Cannot find module 'pg'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/doesdev/pg-ears#readme","github":"https://github.com/doesdev/pg-ears","docs":null,"changelog":null,"pypi":null,"npm":"pg-ears","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}