The models directory contains two modules: Note.js defines the Note class, and notes-memory.js contains an in-memory data model. Both are easy to convert to ES6 modules.
Change the filenames:
$ cd models
$ mv Note.js Note.mjs
$ mv notes-memory.js notes-memory.mjs
In Note.mjs, simply make the following change:
export default class Note {
...
}
This makes the Note class the default export.
Then, in notes-memory.mjs, make the following change:
import Note from './Note';
var notes = [];
async function crupdate(key, title, body) {
notes[key] = new Note(key, title, body);
return notes[key];
}
export function create(key, title, body) { return crupdate(key, title, body); }
export function update(key, title, body) { return crupdate(key, title, body); }
export async function read(key) {
if (notes[key]) return notes[key];
else throw new Error(`Note ${key} does not exist`);
}
export async function destroy(key) {
if (notes[key]) {
delete notes[key];
} else throw new Error(`Note ${key} does not exist`);
}
export async function keylist() { return Object.keys(notes); }
export async function count() { return notes.length; }
export async function close() { }
This is a straightforward transliteration of assigning functions to module.exports to using named exports.
By defining the Note class as the default export of the Note.mjs module, it imports nicely into any module using that class.