I_Jemin

Event is bounded to single Event Emitter, event call won't be global

...@@ -6,9 +6,10 @@ emitter.on('messageLogged', (arg) => { ...@@ -6,9 +6,10 @@ emitter.on('messageLogged', (arg) => {
6 console.log('Listener called',arg); 6 console.log('Listener called',arg);
7 }); 7 });
8 8
9 -emitter.on('logging', (e) => { console.log('Loggin Event',e);}); 9 +const log = require('./logger');
10 +log('message');
11 +
12 +
13 +
10 14
11 -emitter.emit('messageLogged', {id: 1, url: 'http://' });
12 15
13 -// Raise: logging (data: message)
14 -emitter.emit('logging','Jemin');
......
1 -console.log(__filename); 1 +const EventEmitter = require('events');
2 -console.log(__dirname); 2 +const emitter = new EventEmitter();
3 - 3 +var url = 'http:mylogger.io/log';
4 -var url = 'http://mylogger.io/log';
5 4
6 function log(message) { 5 function log(message) {
7 // Send an HTTP request 6 // Send an HTTP request
8 console.log(message); 7 console.log(message);
8 + emitter.emit('messageLogged', {id: 1, url: 'http://' });
9 } 9 }
10 10
11 +
12 +
13 +
14 +
11 module.exports = log; 15 module.exports = log;
......