I_Jemin

Extends Class

const EventEmitter = require('events');
const emitter = new EventEmitter();
const Logger = require('./logger');
const logger = new Logger();
// Register a listener
emitter.on('messageLogged', (arg) => {
logger.on('messageLogged', (arg) => {
console.log('Listener called',arg);
});
const log = require('./logger');
log('message');
logger.log('message');
......
const EventEmitter = require('events');
const emitter = new EventEmitter();
var url = 'http:mylogger.io/log';
function log(message) {
// Send an HTTP request
console.log(message);
emitter.emit('messageLogged', {id: 1, url: 'http://' });
}
// function in class won't need function keyword
class Logger extends EventEmitter {
log(message) {
// Send an HTTP request
console.log(message);
//Raise an event
this.emit('messageLogged', {id: 1, url: 'http://' });
}
}
module.exports = log;
module.exports = Logger;
......