// The module: log.js
const events = require('events');
class Log extends events {
show(s) {
console.log(s);
// Fire (Raise) an event with arguments:
this.emit('gonodego', { id: 88622, name: 'Elizabeth' });
}
}
module.exports = Log;
// The application: app.js
const Log = require('./log');
const log = new Log();
// Register (add) a listener
log.on('gonodego', arg => {
console.log(arg);
});
log.show('node.js');
/*
run:
node.js
{ id: 88622, name: 'Elizabeth' }
*/