Skip to content

Instantly share code, notes, and snippets.

@focusaurus
Created December 6, 2012 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save focusaurus/4228058 to your computer and use it in GitHub Desktop.
Save focusaurus/4228058 to your computer and use it in GitHub Desktop.
Emit events directly from a node module while also exporting functions
var emitterModule = require('./emitter_module');
emitterModule.on("e1", function () {
console.log("emitterModule.e1 handler invoked", arguments);
});
emitterModule.func1();
var EventEmitter = require('events').EventEmitter;
var util = require('util');
function EmitterModule() {
EventEmitter.call(this);
}
util.inherits(EmitterModule, EventEmitter);
var _mod = new EmitterModule();
_mod.func1 = function func1() {
console.log("emitter_module.func1 called, emitting e1");
_mod.emit("e1", 42, 43);
};
module.exports = _mod;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment