May 2018
Intermediate to advanced
492 pages
12h 3m
English
Now, let's look at how to implement the /notes/destroy URL to delete notes.
To routes/notes.js, add the following router function:
// Ask to Delete note (destroy)router.get('/destroy', async (req, res, next) => { var note = await notes.read(req.query.key); res.render('notedestroy', { title: note ? note.title : "", notekey: req.query.key, note: note });});
Destroying a note is a significant step if only because there's no trash can to retrieve it from if we make a mistake. Therefore, we want to ask the user whether they're sure they want to delete that note. In this case, we retrieve the note and then render the following page, displaying a question to ensure they do want to delete the note.
To the views directory, ...
Read now
Unlock full access