January 2018
Beginner
658 pages
13h 10m
English
First up, let's do fetchNotes, which will need the following try-catch block.
I'll actually cut it out of addNote and paste it in the fetchNotes function, as shown here:
var fetchNotes = () => { try{ var notesString = fs.readFileSync('notes-data.json'); notes = JSON.parse(notesString); } catch (e) {}};
This alone is not enough, because currently we don't return anything from the function. What we want to do is to return the notes. This means that instead of saving the result from JSON.parse onto the notes variable, which we haven't defined, we'll simply return it to the calling function, as shown here:
var fetchNotes = () => { try{ var notesString = fs.readFileSync('notes-data.json'); return JSON.parse(notesString); ...Read now
Unlock full access