How Node.js Works
Learn different types of I/O operations in Node.js.
In this lesson, we’ll gain an understanding of how Node.js works internally and be introduced to the reactor pattern, which is the heart of the asynchronous nature of Node.js. We’ll go through the main concepts behind the pattern, such as the single-threaded architecture and the non-blocking I/O, and we’ll see how this creates the foundation for the entire Node.js platform.
I/O is slow
I/O (input/output) is definitely the slowest among the fundamental operations of a computer. Accessing the RAM is in the order of nanoseconds ( seconds), while accessing data on the disk or the network is in the order of milliseconds ( seconds). The same applies to the bandwidth. RAM has a transfer rate consistently in the order of GB/s, while the disk or network varies from MB/s to optimistically GB/s. I/O is usually not expensive in terms of CPU, but it adds a delay between the moment the request is sent to the device and the moment the operation completes. On top of that, we have to consider the human factor. In fact, in many circumstances, the input of an application comes from a real person—a mouse click, for example—so the speed and frequency of I/O doesn’t only ...
Get hands-on with 1400+ tech skills courses.