pg-listen-pid
v1.7.0
Published
pg-listen fork that exposes postgres processId
Downloads
3
Maintainers
Readme
A fork of pg-listen
that exposes the processId from eventemitter.
Installation
# using npm:
npm install pg-listen-pid
Usage
import createSubscriber from "pg-listen-pid"
import { databaseURL } from "./config"
// Accepts the same connection config object that the "pg" package would take
const subscriber = createSubscriber({ connectionString: databaseURL })
subscriber.notifications.on("my-channel", (payload, processId) => {
// Payload as passed to subscriber.notify() (see below)
console.log("Received notification in 'my-channel':", payload, "with PID:", processId)
})
subscriber.events.on("error", (error) => {
console.error("Fatal database connection error:", error)
process.exit(1)
})
process.on("exit", () => {
subscriber.close()
})
export async function connect () {
await subscriber.connect()
await subscriber.listenTo("my-channel")
}
export async function sendSampleMessage () {
await subscriber.notify("my-channel", {
greeting: "Hey, buddy.",
timestamp: Date.now()
})
}
For more details see pg-listen
.
License
MIT