I have 3 files
a.js the shared EventEmitter module
const EventEmitter = require('events');
const myEmitter = new EventEmitter();
module.exports = myEmitter;
b.js the publisher
const myEmitter = require('./a');
// Perform the registration steps
let user = 1;
setInterval(() => {
myEmitter.emit('user-registered', user);
user++;
}, 1000);
// Pass the new user object as the message passed through by this event.
c.js the subscriber
const myEmitter = require('./a');
myEmitter.on('user-registered', (user) => {
// Send an email or whatever.
console.log(user);
});
When I run b.js or the publisher, the events are being published continuously but when I run c.js in a separate window, it immediately quits execution, how do I make this work with the subscriber actually listening to the publisher