Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var addNote = (title, body) => {
- var notes = []; // Create empty array
- var note = { // Fetch user input
- title,
- body
- };
- try {
- var notesString = fs.readFileSync("notes-data.json"); // Get current notes
- notes = JSON.parse(notesString); // convert current notes into object
- console.log("try:", notes.constructor)
- }catch(e){
- }
- console.log(notes)
- notes.push(note);
- fs.writeFileSync("notes-data.json", JSON.stringify(notes));
- };
Add Comment
Please, Sign In to add comment