Registry / messaging / mubsub

mubsub

JSON →
library1.4.0jsnpmunverified

Mubsub is a pub/sub implementation for Node.js and MongoDB using capped collections and tailable cursors. Version 1.4.0 is the latest stable release (no updates since 2016). It allows publishing events to channels backed by capped collections and subscribing with optional event filtering. Compared to other MongoDB pub/sub libraries, it directly leverages MongoDB's native tailable cursors for low-latency message delivery. It is lightweight but lacks modern MongoDB driver support and TypeScript types. Suitable for simple pub/sub within a MongoDB environment.

npm install mubsub
INSTALL
IMPORT
SIG · MUBSUB
M
mubsub
messagingjavascriptv1.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import mubsub from 'mubsub'
const mubsub = require('mubsub')
The package is CommonJS by default; import may require synthetic default imports. Use require() for simplicity.
Client
const client = mubsub('mongodb://...')
const client = new mubsub.Client('mongodb://...')
The default export is a function that returns a client instance. No constructor needed.
Channel
const channel = client.channel('name')
const channel = new mubsub.Channel('name')
Channels are created via client.channel() method, not instantiated directly.

Shows basic usage: create a client, create a channel with options, subscribe to events, publish, then close.

const mubsub = require('mubsub'); const client = mubsub('mongodb://localhost:27017/myapp', {useNewUrlParser: true}); client.on('error', (err) => console.error('Client error:', err)); const channel = client.channel('notifications', {size: 100000, max: 500}); channel.on('error', (err) => console.error('Channel error:', err)); // Subscribe to all events channel.subscribe((message) => { console.log('Received:', message); }); // Subscribe to a specific event channel.subscribe('welcome', (msg) => { console.log('Welcome message:', msg); }); // Publish an event channel.publish('welcome', {user: 'Alice'}); // After some time setTimeout(() => client.close(), 5000);
Debug
Known issues
gotchaDo not create lots of channels because Mubsub polls from the cursor position for each channel, leading to high resource usage.
fix
Limit the number of channels; consider using event names to filter within a single channel instead.
affects: <=1.4.0
gotchaDon't remove collections with running publishers. mongod may recreate the collection as uncapped on next insert before Mubsub can handle it.
fix
Avoid dropping channels while publishing; use a controlled shutdown.
affects: <=1.4.0
deprecatedThe package uses an old MongoDB driver API (e.g., `collection.insert`, `collection.find` with tailable cursor). May not work with newer MongoDB drivers.
fix
Consider using a more modern pub/sub library or pinning an old mongodb driver version (e.g., 2.x).
affects: >=1.4.0
Errors
Common errors & fixes
Error: Cannot find module 'mongodb'
Missing mongodb dependency; mubsub requires it as a peer dependency but doesn't bundle it.
fix
npm install mongodb
TypeError: client.channel is not a function
Using import statement incorrectly; default export is a function returning client, not a class.
fix
Use `const mubsub = require('mubsub')` then `const client = mubsub(uri)`
Upgrade
Version history
1.4.0latest on npm
Audit
Dependencies
mongodbrequiredMongoDB driver required to interact with MongoDB
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
packagemubsub
mubsub — npm install mubsub · libregistry