1.1.1 • Published 8 years ago

mongoose-socket.io-events v1.1.1

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

mongoose-socket.io-events

This plugin emits socket.io events on mongoose hooks. All events are sent on the post hook.

Installation

npm install mongoose-socket.io-events --save

Usage

const mongoose = require('mongoose');
const events = require('mongoose-socket.io-events');

var schema = mongoose.Schema({
  name: String,
  ...
});

schema.use(events, {
  port: 8080
});

Example Event

mongoose:save
{
  id: '' //Document ID
}

Options

OptionTypeDefault Value Description
attachHTTP ServerundefinedA HTTP Server to attach to
eventsObject{save: true, init: true, remove: true, validate: false}Configures the events to broadcast on
namespaceString/The Namespace to use
portNumber80The Port the socket.io Server should run on
prefixStringmongooseA Prefix value for all events
roomString|Boolean_idEither a document path which defines the Room the events shall be broadcasted to or false to broadcast to all sockets
serverSocket.IO ServerundefinedThe Socket.io server instance to use

TODO:

  • configurable payload
  • fixed room name (not document specific)