pg-listener is a lightweight PostgreSQL NOTIFY/LISTEN client designed to work exclusively with pg-promise (v10+). At version 1.1.3, it provides automatic reconnection via retry-async, zero external dependencies besides pg-promise, and full TypeScript support. It simplifies listening to multiple channels on a single connection, supports both event-based and async iterable consumption of notifications, and offers configurable retry strategies for initial and ongoing connections. It differentiates from raw pg-promise usage by abstracting connection management and providing higher-level ergonomics for PostgreSQL notifications.
npm install pg-listenerNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Sets up a pg-promise connection, creates a PgListener, and listens on a PostgreSQL channel with event handler.
Set keepAlive: true (and optionally keepAliveInitialDelayMillis) in the pg-promise connection options.
Use db.none('NOTIFY ...') instead for sending notifications; avoid creating an empty listener unless strictly needed.Update to use createIterable() or the cancel callback. Refer to the IListenResult type.
Upgrade pg-promise to version 10 or newer.
Set explicit retry options if you need predictable retry timing, e.g., retryAll: { retry: 3, delay: () => 1000 }.Run 'npm install pg-listener' and use 'import { PgListener } from 'pg-listener'.Use 'import { PgListener } from 'pg-listener', not 'import PgListener from 'pg-listener'.Ensure tsconfig has 'moduleResolution': 'node' and 'esModuleInterop': true.