All asynchronous I/O operations in node. JS will send an event to the event queue when it is finished. The event is provided by the Eventemitter object.
node. js Event Loop:
The node. JS program starts with the event loop, to the event loop, and all the logic is the callback function of the event. node. js is always in the event loop, and the program entry is the callback function for the first event in the event loop.
The event callback function may issue an I/O request or a direct emission (emit) event during execution, and then return the event sequence after execution, and the event loop checks for any unhandled events in the event queue until the end of the program.
The event loop for node. JS is implemented by the Libev library. Libev supports multiple types of events, Eg:ev_io,ev_timer,ev_signal,ev_idle ... are encapsulated in the Eventemitter package.
Modules (module and package) and packages:
A package can be understood to be a collection of functional modules implemented for publishing and maintenance.
Module: File and module is one by one corresponding, a node. js file is a module, this file may be JavaScript code, JSON or compiled c/s extension.
1. Create the module:
Exports is the interface that the module exposes, and require is used to obtain the interface of a module from the outside, that is, the exports object of the acquired module.
node. JS Learning