Filesystems are an often-overlooked database engine. While filesystems don't have the sort of query features supported by database engines, they are still a reliable place to store files. The Notes schema is simple enough, so the filesystem can easily serve as its data storage layer.
Let's start by adding two functions to the Note class in models/Notes.mjs:
export default class Note {
...
get JSON() {
return JSON.stringify({ key: this.key, title: this.title, body: this.body }); }
static fromJSON(json) { const data = JSON.parse(json);
if (typeof data !== 'object'
|| !data.hasOwnProperty('key')
|| typeof data.key !== 'string'
|| !data.hasOwnProperty('title')
|| typeof data.title !== 'string'
|| !data.hasOwnProperty('body')
|| typeof data.body !== 'string') {
throw new Error(...