Table of Contents
Instead of the process being blocked and waiting for I/O operations to complete, the I/O operations are delegated to the system, so that the process can execute the next piece of code. Non-blocking I/O operations provide a callback function that is called when the operation is completed.
What is blocking in Node JS?
What is the difference between non-blocking and blocking version?
The non-blocking version takes a callback function as a parameter. Some blocking counterpart names generally end with Sync. These functions execute synchronously and block the code. Example of using the file system in both modes:
What is the difference between synchronous and non-blocking methods?
Some methods also have blocking counterparts, which have names that end with Sync. Blocking methods execute synchronously and non-blocking methods execute asynchronously. Using the File System module as an example, this is a synchronous file read: And here is an equivalent asynchronous example: