Making the title unique

The first step to make the title unique will be to loop through all of the notes after we load them in and check whether there are any duplicates. If there are duplicates, we'll not call the following two lines:

notes.push(note);fs.writeFileSync('notes-data.json', JSON.stringify(notes));

If there are no duplicates then it's fine, we will call both of the lines shown in the preceding code block, updating the notes-data file.

Now, we'll be refactoring this function down the line. Things are getting a little wonky and a little out of control, but for the moment, we can add this functionality right into the function. Let's go ahead and make a variable called duplicateNotes.

The duplicateNotes variable will eventually store ...

Get Learning Node.js Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.