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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.