Guest User

Untitled

a guest
Jan 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. var addNote = (title, body) => {
  2. var notes = []; // Create empty array
  3. var note = { // Fetch user input
  4. title,
  5. body
  6. };
  7. try {
  8. var notesString = fs.readFileSync("notes-data.json"); // Get current notes
  9. notes = JSON.parse(notesString); // convert current notes into object
  10. console.log("try:", notes.constructor)
  11. }catch(e){
  12.  
  13. }
  14. console.log(notes)
  15. notes.push(note);
  16. fs.writeFileSync("notes-data.json", JSON.stringify(notes));
  17. };
Add Comment
Please, Sign In to add comment