Skip to content

Instantly share code, notes, and snippets.

@ismnoiet
Created March 28, 2016 11:13
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 ismnoiet/a82ba7bb7329237b0b34 to your computer and use it in GitHub Desktop.
Save ismnoiet/a82ba7bb7329237b0b34 to your computer and use it in GitHub Desktop.
//first.js
var util = require('util'),
EventEmitter = require('events');
function First () {
EventEmitter.call(this)
}
util.inherits(First, EventEmitter);
First.prototype.sendMessage = function (msg) {
this.emit('message', {msg:msg});
};
module.exports = First;
// second.js :
var First = require('./first.js');
var firstEvents = new First();
// listen for the 'message event from first.js'
firstEvents.on('message',function(data){
console.log('recieved data from first.js is : ',data);
});
// to emit message from inside first.js
firstEvents.sendMessage('first message from first.js');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment