node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



Greenkeeper badge

Build Status Code Climate Test Coverage Dependency Status Download Status

Channel functionality for real-time event publishing


feathers-channels provides channel functionality for bi-directional Feathers service providers. It is e.g. used by the and Primus provider to quickly determine what messages to send to connected clients.

npm install feathers-channels --save

Documentation names)

Returns a named or combined channel object.

const channel ='test'); // return a `test` channel
channel.join(connection); // join a channel
channel.leave(connection); // leave a channel
channel.filter(connection => {}) // return a new channel with filtered connections
channel.length // return the number of connections
channel.connections // all connections in this channel
const combined ='test', 'other'); // return a combined channel
combined.join(connection); // join the `test` and `other` channel
combined.leave(connection); // leave the `test` and `other` channel
channel.filter(connection => {}) // return a new channel with filtered connections (connections will only be iterated once)
combined.length // return the number of connections
combined.connections // all connections in the combined channel (if a connection is in multiple channels it will only show once)

app.service('servicename').publish(event, callback), app.service('servicename').publish(callback)

Register a publishing callback for a service and event (or all events) that returns a (named or combined) channel.

app.use('/test', {
  create(data) {
    return Promise.resolve(data);
// `created` event for the `test` service
app.service('test').publish('created', (data, hook) =>'*')
// `created` event for the `test` service, sending different data to two different channels
app.service('test').publish('created', (data, hook) => {
  return ['admins'),'users').send(_.omit(data, 'groups', 'email'))
// All events for all services
app.publish((data, hook) =>'*')
// All `created` events for all services
app.publish('created', (data, hook) =>'*')
// All events for `test` service
app.service('test').publish((data, hook) =>'*')

app.on('publish', function(event, channel, hook) {})

An event that will be sent every time a service event that has connections to publish to happens. channel is a combined channel with all connections to publish the event to.

Note: If there are no channels or connections the publish event will not be sent.

app.on('publish', (event, channel, hook) => {
  channel.connections.forEach(connection => {
    // Do something with `connection`


Copyright (c) 2017

Licensed under the MIT license.