Skip to content

What's the reason for this library to exist? #39

@punkpeye

Description

@punkpeye

Hey,

I am just getting familiar with notifications in postgres.

Why can't I just do something like:

const { Client } = require('pg');
const connectionString = process.env.DATABASE_URL;
const client = new Client({ connectionString });
async function listenToNotifications() {
  try {
    // Connect to Postgres
    await client.connect();
    // Listen to specific channel in Postgres
    // Attach a listener to notifications received
    client.on('notification', (msg) => {
      console.log('Notification received', msg.payload);
    });
    await client.query('LISTEN channel_name');
    console.log('Listening for notifications on my_channel');
  } catch (e) {
    console.log(e);
  }
}

What purpose does this library serve that's not covered by this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions