const EventEmitter = require('events');
class Logger extends EventEmitter {
log(message) {
// Log the message
console.log(message);
// Raise an event
this.emit('messageLogged', { id: 1, url: 'http://' });
}
}
module.exports = Logger;
Content of the index fileconst Logger = require('./logger');
const logger = new Logger();
// Register a listener
logger.on('messageLogged', function(arg) {
console.log('Listener called', arg);
});
logger.log('message');