Filling out the in-memory Notes model

Create a file named notes-memory.js in the models directory, with this code:

const Note = require('./Note');var notes = [];exports.update = exports.create = async function(key, title, body) {    notes[key] = new Note(key, title, body);    return notes[key];};exports.read = async function(key) {    if (notes[key]) return notes[key];    else throw new Error(`Note ${key} does not exist`);};exports.destroy = async function(key) {    if (notes[key]) {        delete notes[key];    } else throw new Error(`Note ${key} does not exist`);};exports.keylist = async function() { return Object.keys(notes); };exports.count = async function() { return notes.length; };exports.close = async function() { }

This is a simple in-memory data store that's ...

Get Node.js Web Development - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.