A generic Node.js style event handler as a class property
Last updated 2 years ago by bret .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install node-event-handler 
SYNC missed versions from official npm registry.


npm version build status coverage downloads js-standard-style

A generic Node.js style event handler.


$ npm install node-event-handler


const NodeEventHandler = require('node-event-handler')
const WebSocket = require('ws')

class MyWSController extends SomeOtherClass {
  constructor () { = new WebSocket('ws://localhost:8080')
    this.handler = new NodeEventHandler(this,

  // These methods handle the websocket events
  onmessage (data) {}
  onopen () {}
  onerror (error) {}
  onclose () {}


handler = new NodeEventHandler(ctx, [ee])

Create a new instance of NodeEventHandler passing in a context ctx (often this when created within a class) and optionally a Node.js style event emitter ee to attach listeners to on instantiation.

The ctx should be an object who's prototype contains event handler methods. Event handler methods must take the form of on${eventname} where eventname is the name of the event you want to listen on and handle (the name you would pass to ee.on(eventname)). In practice, you can pass a class instance as a ctx, or this when the instance owns the NodeEventHanlder instance.


Attach all event handler methods on ctx to the Node.js style event emitter ee.


Remove all event handler event names on ctx from the Node.js style event emitter ee.

See also

This module is an API match to dom-event-handler which has a clever API, but requires the support of the handleEvent on the EventListener interface. Most Node.js modules have poor support for these interfaces because they are difficult to replicate outside of a browser.

When using dom-event-handler in a universal context, this can be used as a stand-in on the Node.js side of things.



Current Tags

  • 1.0.1                                ...           latest (2 years ago)

2 Versions

  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (0)
Dev Dependencies (13)

Copyright 2014 - 2016 © |