Creating a mock database

The load-assets.js file also contains a method for creating a mock database instance:

const loadDb = () => {
const dbPath = path.resolve(assetsPath, 'db.json');
const adapter = new FileSync(dbPath);
return low(adapter);
};

The loadDb() function loads the contents of /assets/db.json into an instance of lowdb. The default function exported from load-assets.js calls the loadWasm() and loadDb() functions and returns an object containing the mock database and Wasm instance:

module.exports = async function loadAssets() {
const db = loadDb();
const wasmInstance = await loadWasm();
return {
db,
wasmInstance
};
};

Going forward, I'll use the term database to refer to the lowdb instance that accesses the db.json file. Now that the assets are loaded, let's review how the application interacts with them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset