events
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
"Events" is a helpful package in Node.js that aims to implement Node's event emitter for all engines. It is specially created for those environments that do not have the Node.js events
module, like browsers. The package brings the functionality of the events
module according to the Node.js 11.13.0 API. Being built on ES5 features, it requires an es5-shim
for support in older browsers like IE8. Remember that this package is typically built-in with Node.js and also included in bundlers like Browserify or Webpack.
To use the events
package, you must first install it via npm with the command npm install events
. However, if your code runs in Node.js or in the browser via a bundler like Browserify or Webpack, the events
module is likely already included. After the installation, you can require the events
module into your Javascript file.
Here is a simple usage example:
var EventEmitter = require('events')
var ee = new EventEmitter()
ee.on('message', function (text) {
console.log(text)
})
ee.emit('message', 'hello world')
In this example, a new instance of EventEmitter
is created. The ee.on
method is then used to specify the 'message' event and its corresponding callback function that will execute when the event occurs. The ee.emit
method triggers the 'message' event and passes 'hello world' as text.
As for the documentation, events
provides an exact match to the Node.js API (specifically Node.js 11.13.0). Thus, the complete documentation for the events
module can be found at the Node.js 11.13.0 EventEmitter documentation. It is also worth mentioning that contributions to this package are encouraged, particularly through porting features, bugfixes, and tests from Node.js.