Affiliate link

Node.js Functions - Events

In Node.js, events are a core part of the platform's asynchronous, event-driven architecture. The Node.js EventEmitter class is used to handle and emit events.

When an event occurs, an event object is created and passed to any registered event listeners. The event listeners can then perform some action in response to the event.

const EventEmitter = require('events');

const myEmitter = new EventEmitter();

myEmitter.on('myEvent', () => {
    console.log('My event was triggered');
});

myEmitter.emit('myEvent');
Affiliate link
Affiliate link
Advertisment
Fiverr
Get Surfshark VPN