const EventEmitter = require('events')
const myEmitter = new EventEmitter();
myEmitter.emit('newSale') //give name
//setup listener
myEmitter.on("newSale", ()=> {console.log("There was a new sale!")})
myEmitter.emit("newSale")
const events = require('events');
let emitter = new events.EventEmitter();
emitter.on('newEvent', (message)=>{
console.log(`Message : ${message}`);
});
emitter.emit('newEvent', 'Hello guys, this is CodezUp');
const EventEmitter = require('events');
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
myEmitter.on('event', () => {
console.log('an event occurred!');
});
myEmitter.emit('event');
import { EventEmitter } from "node:events";
/**
* add "type":"module" in package.json
*/
class MyEmitter extends EventEmitter {}
const myEvent = new MyEmitter();
myEvent.on("event", () => {
console.log("an event occurred!");
});
myEvent.emit("event");