From 15a11f8ac9a74d6aa597e4729194eba6e26ce0e1 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Sun, 11 Aug 2019 13:17:40 -0600 Subject: [PATCH] Video 23 --- notes-app/app.js | 2 +- notes-app/notes.js | 12 +++++++++++- notes-app/notes.json | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/notes-app/app.js b/notes-app/app.js index 6970465..df0b14f 100644 --- a/notes-app/app.js +++ b/notes-app/app.js @@ -47,7 +47,7 @@ yargs.command({ command: 'list', describe: 'List notes', handler() { - console.log('Listing out all notes'); + notes.listNotes(); } }); diff --git a/notes-app/notes.js b/notes-app/notes.js index 976abea..fec9469 100644 --- a/notes-app/notes.js +++ b/notes-app/notes.js @@ -34,6 +34,15 @@ const removeNote = (title) => { } } +const listNotes = () => { + const notes = loadNotes(); + + console.log(chalk.cyan.underline('Your notes:')); + notes.forEach((note) => { + console.log(note.title); + }); +} + const saveNotes = (notes) => { const dataJSON = JSON.stringify(notes); fs.writeFileSync('notes.json', dataJSON); @@ -52,5 +61,6 @@ const loadNotes = () => { module.exports = { getNotes: getNotes, addNote: addNote, - removeNote: removeNote + removeNote: removeNote, + listNotes: listNotes } diff --git a/notes-app/notes.json b/notes-app/notes.json index 958e08e..1fe2af7 100644 --- a/notes-app/notes.json +++ b/notes-app/notes.json @@ -1 +1 @@ -[{"title":"List","body":"Sweater, Pants"}] \ No newline at end of file +[{"title":"List","body":"Sweater, Pants"},{"title":"Course Ideas","body":""}] \ No newline at end of file