January 2018
Beginner
658 pages
13h 10m
English
Now, the same thing will go for saveNotes just as in the case of the fetchNotes function. The saveNotes function will take the notes variable and it will say this using fs.writeFileSync. I will cut out the line in addNote that does this (that is, fs.writeFileSync('notes-data.json', JSON.stringfy(notes));) and paste it in the saveNotes function, as shown here:
var saveNotes = (notes) => { fs.writeFileSync('notes-data.json', JSON.stringify(notes));};
Now, saveNotes doesn't need to return anything. In this case, we'll copy the line in saveNotes and then call saveNotes in the if statement of the addNote function, as shown in the following code:
if (duplicateNotes.length === 0) { notes.push(note); saveNotes();}
This might ...
Read now
Unlock full access