All actions on a computer, such as clicking a button or opening a file, are considered events. Events allow the developer to create a non-blocking, asynchronous flow of control in their application.
When a script needs to fetch data from a database, it will send the request and continue execution without waiting for a reply. When the data is returned, an event is triggered, and a callback function is executed.
This allows the script to continue executing other tasks while it is waiting for the data to be returned, rather than being blocked. With this, the application is no longer reliant on a traditional blocking, synchronous flow of control.
In Node.js, objects have the ability to trigger events. There are several built-in objects that can trigger events. The most common of such built-in objects include:
setTimeout() and setInterval() functions in Node.js are built on top of the Timers module, which allows the triggering events at specific time intervals.fs module in Node.js can trigger events when a file is opened, closed, or when data is read from a file.The Events module in Node.js is a built-in module that allows developers to create, fire and listen for their own custom events. It provides an event emitter class that can be used to create objects that can emit events and register listeners for those events.
To include built-in Events module in our project, we can use the require() method. The module provides an EventEmitter class. To be able to access these properties and methods we’ll need for managing events, we then need to create an instance of the EventEmitter object.

This instance of the EventEmitter object can be used to create, emit, and listen for custom events.
The most vital methods to the Event Emitter object are the "emit" method, which is used to fire an event, and the "on" method, which is used to register a listener. The “once” method is notable as well, used to register one-time listeners.
The ‘on’ method is used to register a listener for a specific event. When an event is triggered by the emit() method, the function called by ‘on’ is executed.
The basic syntax for the ‘on’ method involves calling the on() method through EventEmitter, then entering the name of the event and the function we want to call when an event is triggered: