Rewriting router modules as ES6 modules

The routes directory contains two router modules. As it stands, each router module creates a router object, adds route functions to that object, and then assigns it to the module.exports field. That suggests we should export the router as the default export, but as we said earlier, that didn't work out right. Instead, we'll export router as a named export.

Change the filenames:

$ cd routes$ mv index.js index.mjs$ mv notes.js notes.mjs

Then, at the top of each, change the require statement block to the following:

import util from 'util';import express from 'express';import * as notes from '../models/notes-memory';export const router = express.Router();

It will be the same in both files. Then, at the ...

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.