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));
// 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.
1 Reply
reactibot
reactibot3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1003889447290540172 Question not getting answered? Maybe it's hard to answer, or maybe you asked at a slow time. Check out these resources for help asking a good question: https://stackoverflow.com/help/how-to-ask http://wp.me/p2oIwo-26