eventemitter2
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
EventEmitter2 is an advanced event emitter implementation for Node.js. It has remarkable features such as namespaces, wildcards, times to listen (TTL), asynchronous listeners, and more. EventEmitter2 is fully compatible with Node.js and browsers or workers of any kind and is enriched with non-breaking features thus improving the standard EventEmitter module.
To use EventEmitter2, first install it in your Node.js project via npm:
$ npm install eventemitter2
Import it into your JavaScript file:
const EventEmitter2 = require('eventemitter2');
Then create a new instance of EventEmitter2:
var emitter = new EventEmitter2({
wildcard: true,
delimiter: '.',
newListener: false,
removeListener: false,
maxListeners: 10,
verboseMemoryLeak: false,
ignoreErrors: false
});
To listen for an event, use the on
method:
emitter.on('foo', function(data) {
console.log('An event occurred!', data);
});
To emit an event, use the emit
method:
emitter.emit('foo', { some: 'data' });
Events can be emitted and listened multiple times or only once, and have support for namespaces and wildcards.
The complete documentation of EventEmitter2 is available on its official Github repository.