npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pg-ipc

v1.0.5

Published

IPC over PostgreSQL LISTEN/NOTIFY/UNLISTEN exposed as an EventEmitter

Downloads

9,954

Readme

pg-ipc

IPC over PostgreSQL LISTEN/NOTIFY/UNLISTEN exposed as an EventEmitter

Usage

var pgIPC = require('pg-ipc')
var client = new require('pg').Client({ ... })

var ipc = pgIPC(client)

ipc.on('error', console.error)

ipc.on('end', function () {
  client.end()
})

ipc.on('someChannel', function (msg) {
  // Ignore messages from this process
  if (msg.processId === client.processID) return
  console.log(msg.payload.currentTime)
})

ipc.notify('someChannel', {currentTime: Date.now()})

// some time later ...

ipc.end()

API

pgIPC(client)

Instantiates a new EventEmitter with the appropriate hooks to automatically LISTEN/NOTIFY/UNLISTEN. Note that client must be a pg.Client instance and not a pg.Pool, as a single connection is required.

ipc.on(channel, listener)

All the standard EventEmitter methods are exposed. When a listener is added to channel, a LISTEN command is automatically issued, and UNLISTEN when the number of listeners reach zero. The listener will receive the message as its first argument. Notable properties being channel, payload, processId. Each postgres connection is assigned a unique processId, which can be used to ignore messages from the same process. See EventEmitter for more details. Reserved channels are: ['newListener', 'removeListener', 'notify', 'unlisten', 'listen', 'error', 'end']

ipc.notify(channel[, payload])

Alias: ipc.send(channel[, payload]). Send a message to channel with optional payload. payload is transparently converted to JSON where appropriate.

ipc.end()

Issue UNLISTEN * if connected, emit end and detach all event listeners. Does not call client.end() so you can continue using the client. However, any listeners you've issued outside outside of this module will also be detached

Event: listen

Emitted when a LISTEN has been successfully issued. Passed channel

Event: notify

Emitted after a notification has been successfully sent. Passed channel and payload

Event: unlisten

Emitted when a UNLISTEN has been successfully issued. Passed channel

Event: end

Emitted when all LISTENs have been removed, but before all event listeners are removed.

Event: error

Propagates any errors caused by queries on Client. Passed the err argument from the query callback.

Install

npm install pg-ipc

License

ISC