Chapter 2. Node.js Essential Patterns
Embracing the asynchronous nature of Node.js is not trivial at all, especially if coming from a language such as PHP where it is not usual to deal with asynchronous code.
In synchronous programming, we are used to the concept of imagining code as a series of consecutive computing steps defined to solve a specific problem. Every operation is blocking, which means that only when an operation is completed is it possible to execute the next one. This approach makes the code easy to understand and debug.
Instead, in asynchronous programming, some operations, such as reading a file or performing a network request, can be executed as an operation in the background. When an asynchronous operation is invoked, the next one is executed immediately, even if the previous operation has not finished yet. The operations pending in the background can complete at any time, and the whole application should be programmed to react in the proper way when an asynchronous...