javascript
Published on January 26, 2024By DeveloperBreeze
// Import 'events' module
const EventEmitter = require('events');
// Create an EventEmitter instance
const emitter = new EventEmitter();
// Define an event listener
emitter.on('event', () => {
console.log('Event occurred');
});
// Emit the 'event' to trigger the listener
emitter.emit('event');
Comments
Please log in to leave a comment.