Skip to content

Instantly share code, notes, and snippets.

@dominicbartl
Last active March 3, 2018 21:23
Show Gist options
  • Save dominicbartl/6318101 to your computer and use it in GitHub Desktop.
Save dominicbartl/6318101 to your computer and use it in GitHub Desktop.
2 ways to inherit from EventEmitter in Node.JS
var EventEmitter = require('events').EventEmitter;
module.exports = new EventEmitter();
exports.emitSomethingLater = function()
setTimeout(function() {
module.exports.emit('something');
}, 1000);
}
var util = require("util"),
events = require("events");
function CustomEmitter (opts){
events.EventEmitter.call(this);
}
util.inherits(CustomEmitter, events.EventEmitter);
CustomEmitter.prototype.emitSomething = function() {
this.emit('something');
};
module.exports = CustomEmitter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment