May 2018
Intermediate to advanced
492 pages
12h 3m
English
Now that we've looked at how to create notes, we need to move on to reading them. This means implementing controller logic and view templates for the /notes/view URL.
To routes/notes.js, add this router function:
// Read Note (read)router.get('/view', async (req, res, next) => { var note = await notes.read(req.query.key); res.render('noteview', { title: note ? note.title : "", notekey: req.query.key, note: note });});
Because this route is mounted on a router handling /notes, this route handles /notes/view.
If notes.read successfully reads the note, it is rendered with the noteview template. If something goes wrong, we'll instead display an error to the user through Express.
To the views directory, add the noteview.hbs ...
Read now
Unlock full access