Skip to content

Instantly share code, notes, and snippets.

@fideloper
Last active October 17, 2016 04:05
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save fideloper/4651109 to your computer and use it in GitHub Desktop.
Save fideloper/4651109 to your computer and use it in GitHub Desktop.
Using Event Emitter in your node modules
var Fancy = require('FancyModule');
var mod = new Fancy();
mod.on('success', function(data) {
console.log(data); // { this_is_fancy:'indubitably' }
});
var EventEmitter = require('events').EventEmitter;
function FancyModule() {
EventEmitter.call(this);
// And other fancy code
}
FancyModule.prototype = Object.create(EventEmitter.prototype);
FancyModule.prototype.fancified = function() {
// Just one of many fancy functions available in my fancy module
var fancyData = { this_is_fancy:'indubitably' };
this.emit('success', fancyData);
}
module.exports = FancyModule;
@fideloper
Copy link
Author

quite fancy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment