a library to communicate your code using publisher/subscriber pattern

Usage no npm install needed!

<script type="module">
  import adessaNodePubsub from 'https://cdn.skypack.dev/@adessa-node/pubsub';



It's a library that provides you a way to communicate your code using publisher/subscriber pattern.

API Methods

  • on
  • subscribe
  • publish
  • notify
  • getChannels
  • removeChannels

on(eventName, listener)

Attaches a listener to a specific event, so when that channel gets a notification, the listener will be triggered.


  • eventName (string): the channel which is going to be used to register the listener.
  • listener (Function): the callback to be triggered when channel receives an event.


  • dispose (Function): a dispose function to be called when this listener needs to be removed.


const dispose = pubsub.on('myEvent', (arg) => {
  console.log('this is the arg i am receiving', arg);

dispose(); // this listener won't be here any longer


Alias of on

publish(eventName[, ...args])

publishes on a channel an event and sends the arguments.

  pubsub.publish('a channel', 'one');


Alias of publish

getChannels => string[]

  const noop = () => {};
  pubsub.on('channel1', noop);
  pubsub.on('channel2', noop);

  // more lines of code

  const registeredChannels = pubsub.getChannels();
  // => [channel1, channel2]


it will remove every channel listener put into pubsub