Real-time changes in the Notes home page

The Notes model now sends events as Notes are created, updated, or destroyed. For this to be useful, the events must be displayed to our users. Making the events visible to our users means the controller and view portions of the application must consume those events.

Let's start making changes to routes/index.mjs:

router.get('/', async (req, res, next) => {  try {    let notelist = await getKeyTitlesList();    res.render('index', {       title: 'Notes', notelist: notelist,      user: req.user ? req.user : undefined    });  } catch (e) { next(e); }});

We need to reuse part of the original routing function, to use it in another function. Therefore, we've pulled code that used to be in this block into a new function, getKeyTitlesList ...

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.