§8.2.

What’s missing?

The shopping list application has a severe problem. Shopping list items are not persistent. If you restart the server by pressing Control+C, all of the shopping list items are lost.

The problem lies in the persistence layer (see chapter08_memory/persistence.js):

// Underlying data store, an array of { description: string, quantity: number }
let itemData = [];

// Retrieve all items in the shopping list
// returns an array of { description: string, quantity: number }
function findAllItems() {
    return itemData;
}

// Insert a single item into the shopping list
// description is a string, quantity is an integer
// the parameters are assumed to be valid (non-null, non-empty)
function insertItem(description, quantity) {
    itemData.push({ description, quantity });
}

module.exports = { findAllItems, insertItem };

The array itemData is only stored in memory. It is never saved to disk.