Skip to content

ncuillery/single-events-eventemitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

single-events-eventemitter

Build Status

When you have to use the Node.js event API, you have to create an instance of EventEmitter. If a module B has to listen event emitted from module A, you can simply require A in B and do something like this:

moduleA.on('notification', function () {
  // Do something
});

But if you need an single instance shared by multiple emitters and listeners (kind of an event bus) then you need to wrap your instance in a module like this:

var EventEmitter = require('events').EventEmitter;
var eventEmitter = new EventEmitter();
module.exports = eventEmitter;

These 3 lines of code are exactly what this package will spare you and it's its sole purpose 😉

About

Simple instance of the Node.js EventEmitter, available as singleton through your whole app.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published