Instantly share code, notes, and snippets.

@fideloper /app.js
Last active Oct 17, 2016

What would you like to do?
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() {;
// 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;

This comment has been minimized.


fideloper commented Jan 27, 2013

quite fancy

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