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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@darkhogg/pubsub

v0.3.0

Published

[![npm (scoped)](https://img.shields.io/npm/v/@darkhogg/pubsub.svg)](https://www.npmjs.com/package/@darkhogg/pubsub)

Downloads

34

Readme

@darkhogg/pubsub

npm (scoped)

A simple Publish/Subscribe system with persistent messages that uses MongoDB as a backend.

This is a toy project, created mostly to prove a point. It is usable and might solve somebody's problem, but its feature set is unlikely to grow. You are still welcome to report bugs or suggest improvements, and I will try to find time to look at them.

Usage

The API is really simple, most of it can be understood just by looking at the examples directory.

You should import this library as follows:

const {createPubSub} = require('@darkhogg/pubsub');

createPubSub(mongoUri, {bucket, clientName, startDate})

Returns a promise to a PubSub client that connects to the given mongoUri. The client will respect the database given by the URI.

  • bucket is used as the prefix of all collections. Defaults to 'pubsub'.
  • clientName is a string is used to identify this client and is used to determine which events were already consumed by it. No more that one client with the same name will ever consume the same message. Defaults to 'default'.
  • startDate is a Date determining the first date at which this client is interested in events. This is useful to prevent processing a huge number of past events for new clients that are only interested in future events. Defaults to new Date(0) (that is, 1970-01-01T00:00:00.000Z)

Note that this is the only exported symbol by the library itself.

PubSub.channel(channelName)

Returns a promise to a Channel with the given channelName. Channels are cached, so multiple calls to this method will resolve to the same object. Each channel comes with its own collection in the database.

PubSub.disconnect()

Disconnects the client and returns a promise to the successful disconnection. this will stop all channels and close the MongoDB connection. The client or any channels created by it are unusable after this call.

Channel.publish(name, body)

Publishes a message with the given name and body in this channel. Returns a promise that resolves after the message was published.

Channel.subscribe(name, callback)

Registers the callback to be called whenever a message with the given name is published. the callback is called with the message body as its argument. Returns a Subscription.

Channel.unsubscribeAll()

Cancels all subscription to this channel. No more messages will arrive to any subscriptors of this channel object.

New subscriptions can still be created normally after this call.

Subscription.unsubscribe

Cancel the subscription. No more messages will arrive to this particular subscriptor, but others will still receive messages.

New subscriptions can still be created normally after this call.