pg-notify (v1.0.6) is a lightweight Postgres pub/sub client using PostgreSQL's built-in NOTIFY/LISTEN commands, built on top of the popular pg library. It provides automatic reconnection, payload size validation (default max 7999 bytes to match PostgreSQL's limit), and channel/payload sanitization. Active maintenance with frequent releases, focused on simplicity and minimal overhead compared to alternatives like pg-pubsub or message brokers.
npm install pg-notifyNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Connects to PostgreSQL, subscribes to 'chat' channel, emits two messages, waits, then closes.
Ensure you parse manually if sending non-JSON strings. Objects are automatically serialized and deserialized.
Set maxPayloadSize option if you have reconfigured PostgreSQL's max_notify_payload_length.
Use removeListener(listener) as documented.
Use a singleton pubsub instance per connection string or share a pool if needed.
Always await pubsub.connect() before using pubsub.
Await pubsub.connect() before subscribing: await pubsub.connect(); await pubsub.on(...)
Use default import: import PGPubSub from 'pg-notify'
Reduce payload size or increase maxPayloadSize option up to PostgreSQL's max_notify_payload_length.
Shorten channel name to 63 characters or less.