Storing notes in the filesystem

The filesystem is an often overlooked database engine. While filesystems don't have the sort of query features supported by database engines, they are a reliable place to store files. The notes schema is simple enough that the filesystem can easily serve as its data storage layer.

Let's start by adding a function to Note.mjs:

export default class Note {   ...   get JSON() {       return JSON.stringify({ 
        key: this.key, title: this.title, body: this.body 
      }); 
   }   static fromJSON(json) { 
       var data = JSON.parse(json); 
       var note = new Note(data.key, data.title, data.body); 
       return note; 
   } }

JSON is a getter, which means it gets the value of the object. In this case, the note.JSON attribute/getter, no parentheses, will simply give ...

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.