Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@nodebb/mubsub
Advanced tools
Pub/sub for Node.js and MongoDB, updated for mongodb 3.0.x by nodebb
Mubsub is a pub/sub implementation for Node.js and MongoDB. It utilizes Mongo's capped collections and tailable cursors to notify subscribers of inserted documents that match a given query.
var mubsub = require('mubsub');
var client = mubsub('mongodb://localhost:27017/mubsub_example');
var channel = client.channel('test');
client.on('error', console.error);
channel.on('error', console.error);
channel.subscribe('bar', function (message) {
console.log(message.foo); // => 'bar'
});
channel.subscribe('baz', function (message) {
console.log(message); // => 'baz'
});
channel.publish('bar', { foo: 'bar' });
channel.publish('baz', 'baz');
You can pass a Db instance or a URI string. For more information about the URI format visit http://mongodb.github.io/node-mongodb-native/driver-articles/mongoclient.html
var mubsub = require('mubsub');
// Using a URI
var client = mubsub('mongodb://localhost:27017/mubsub_example', [options]);
// Passing a MongoDB driver `Db` instance directly.
var client = mubsub(new Db(...));
A channel maps one-to-one with a capped collection (Mubsub will create these if they do not already exist in the database). Optionally specify the byte size of the collection and/or the max number of documents in the collection when creating a channel.
WARNING: You should not create lots of channels because Mubsub will poll from the cursor position.
var channel = client.channel('foo', { size: 100000, max: 500 });
Options:
size
max size of the collection in bytes, default is 5mbmax
max amount of documents in the collectionretryInterval
time in ms to wait if no docs are found, default is 200msrecreate
recreate the tailable cursor when an error occurs, default is trueWARNING: Don't remove collections with running publishers. It's possible for mongod
to recreate the collection on the next insert (before Mubsub has the chance to do so). If this happens the collection will be recreated as a normal, uncapped collection.
var subscription = channel.subscribe([event], callback);
Subscriptions register a callback to be called whenever a document matching the specified event is inserted (published) into the collection (channel). You can omit the event to match all inserted documents. To later unsubscribe a particular callback, call unsubscribe
on the returned subscription object:
subscription.unsubscribe();
channel.publish(event, obj, [callback]);
Publishing a document simply inserts the document into the channel's capped collection. A callback is optional.
The following events will be emitted:
// The given event was published
channel.on('myevent', console.log);
// Any event was published
channel.on('message', console.log);
// Document was inserted
channel.on('document', console.log);
// Mubsub is ready to receive new documents
channel.on('ready', console.log);
// Connection error
client.on('error', console.log);
// Channel error
channel.on('error', console.log);
client.close();
Closes the MongoDB connection.
npm install mubsub
make test
You can optionally specify the MongoDB URI to be used for tests:
MONGODB_URI=mongodb://localhost:27017/mubsub_tests make test
FAQs
Pub/sub for Node.js and MongoDB, updated for mongodb 3.0.x by nodebb
The npm package @nodebb/mubsub receives a total of 4 weekly downloads. As such, @nodebb/mubsub popularity was classified as not popular.
We found that @nodebb/mubsub demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.