BIOLOGY SCIENCE – 04-58 Aug 2

1. how can i communicate between js files via events ?
im thinking something like this
// emitter file
const events = require('events');
const event = new events();

module.exports = event;

event.emit('myEvent', 'some data');

// some other file which i want to listen to
const event = require('path/to/emitter');
event.addListener('myEvent', (e) => console.log(e));

2. what is the best way to communicate between js files.
condition: not primarily by module.exports, like it should not be the main thing which transports the data but it can help in doing so like i did in case 1.
Was this page helpful?