Asynchronizing the Notes application
The previous Notes application used a synchronous model for accessing the data model. We got away with that because the data was stored in memory, and there was no need to access model data via asynchronous functions. However, by storing the data in a database, we're in territory where we must access the data via asynchronous functions. Recall the discussion in Chapter 1, About Node, about the original reasoning behind Node's asynchronous architecture. Accessing data in memory takes a few clock cycles making it possible to directly operate on in-memory data without delays that would prevent the Node server from handling events. Data stored anywhere else, even in the memory space of another process, requires a delay to access that data, and any delay prevents the Node server from handling events.
Hence, converting the Notes application to use asynchronous operations to access the data is going to require some surgery.
What we're going to do is as follows...