Node.js: Remembering that data storage requires asynchronous code

By definition, external data storage systems require asynchronous coding techniques, such as the ones we discussed in previous chapters. The core principle of the Node.js architecture is that any operation that requires a long time to perform must have an asynchronous API in order to keep the event loop running. The access time to retrieve data from a disk, another process, or a database always needs to take sufficient time to require deferred execution.

The existing Notes data model is an in-memory datastore. In theory, in-memory data access does not require asynchronous code and, therefore, the existing model module could use regular functions, rather than async functions.

We know that Notes should use databases and it requires an asynchronous API to access the Notes data. For this reason, the existing Notes model API uses async functions, so in this chapter, we can persist the Notes data to databases.

That was a useful refresher. Let’s now talk about one of the administrative details required for a production application—using a logging system to store the usage data.

Source: Herron David (2020), Node.js Web Development: Server-side web development made easy with Node 14 using practical examples, Packt Publishing.

Leave a Reply

Your email address will not be published. Required fields are marked *