In order to get started, all we need to do is fill out the list notes function, which in this case we called getAll. The getAll function is responsible for returning every single note. That means it's going to return an array of objects, an array of all of our notes.
All we have to do that is to return fetchNotes, as shown here:
var getAll = () => {
return fetchNotes();
}
There's no need to filter, there's no need to manipulate the data, we just need to pass the data from fetchNotes back through getAll. Now that we have this in place, we can fill out the functionality over inside of app.js.
We have to create a variable where we can store the notes, I was going to call it notes, but I probably shouldn't because we already have a notes variable declared. I'll create another variable, called allNotes, setting it equal to the return value from getAll, which we know because we just filled out returns all the notes:
else if (command === 'list') {
var allNotes = notes.getAll();
}
Now I can use console.log to print a little message and I'll use template strings so I can inject the actual number of notes that are going to be printed.
Inside the template strings, I'll add Printing, then the number of notes using the $ (dollar) sign and the curly braces, allNotes.length: that's the length of the array followed by notes with the s in parenthesis to handle both singular and plural cases, as shown in the following code block:
else if (command === 'list') {
var allNotes = notes.getAll();
console.log(`Printing ${allNotes.length} note(s).`);
}
So, if there were six notes, it would say printing six notes.
Now that we have this in place, we have to go about the process of actually printing each note, which means we need to call logNote once for every item in the allNotes array. To do, this we'll use forEach, which is an array method similar to filter.
Filter lets you manipulate the array by returning true or false to keep items or remove items; forEach simply calls a callback function once for each item in the array. In this case we can use it using allNotes.forEach, passing in a callback function. Now, that callback function will be an arrow function (=>) in our case, and it will get called with the note variable just like filter would have. And all we'll call is notes.logNote, passing in the note argument, which is right here:
else if (command === 'list') {
var allNotes = notes.getAll();
console.log(`Printing ${allNotes.length} note(s).`);
allNotes.forEach((note) => {
notes.logNote(note);
});
}
And now that we have this in place, we can actually simplify it by adding the logNote call, as shown in here:
else if (command === 'list') {
var allNotes = notes.getAll();
console.log(`Printing ${allNotes.length} note(s).`);
allNotes.forEach((note) => notes.logNote(note));
}
This is the exact same functionality, only using the expression syntax. Now that we have our arrow function (=>) in place, we are calling notes.logNote once for each item in the all notes array. Let's save the app.js file and test this out over in Terminal.
In order to test out the list command, all I'll use is node app.js with the command list. There is no need to pass in any arguments:
node app.js list
When I run this, I do get Printing 3 note(s) and then I get my 3 notes to buy, to buy from store, and things to do, as shown in the following code output, which is fantastic:

With this in place, all of our commands are now working. We can add notes, remove notes, read an individual note, and list all of the notes stored in our JSON file.
Moving on to the next section, I want to clean up some of the commands. Inside app.js and notes.js, we have some console.log statements that are printing out a few things we no longer need.
At the very top of app.js, I am going to remove the console.log('Starting app.js') statement, making the constant fs the first line.
I'll also remove the two statements: console.log('Command: ', command) and console.log('Yargs', argv) that print the command and the yargs variable value.
Inside notes.js, I will also remove the console.log('Stating notes.js') statement at the very top of that file, since it is no longer necessary, putting constant fs at the top.
It was definitely useful when we first started exploring different files, but now we have everything in place, there's no need. If I rerun the list command, this time you can see it looks a lot cleaner:

Printing three notes is the very first line showing up. With this in place, we have done our commands.
In the next section, we're going to take a slightly more in-depth look at how we can configure yargs. This is going to let us require certain arguments for our commands. So if someone tries to add a note without a title, we can warn the user and prevent the program from executing.