Let's look at one of the methods from our games service:
module.exports.get = (id) => games.find(game => game.id === id);
The interface of this function is synchronous: you call it and get a value back. Chapter 4, Introducing Node.js Modules, introduced the games service as the module responsible for how we store our games. The interface shouldn't need to change if we change the storage implementation. This isn't quite the case at the moment, though.
As discussed before, most Node.js libraries are asynchronous. Synchronous interfaces can't make use of asynchronous implementations. Let's say the get
function wants to make use of an asynchronous method in a third-party datastore
library. What would that look like? The comments in the following (non-working) code describe the problem:
module.exports.get = (id) => { datastore.getById(id, (err, result) => { // Result available, but outer method has already returned }); ...