【发布时间】:2019-01-27 19:04:23
【问题描述】:
我的代码中的 "notes = JSON.parse(fs.readFileSync("notes-data.json"))" 行似乎无法正常工作...
当我添加新注释时,它应该添加到 .json 文件中的数组中,但它只是替换了以前的注释。
let addNote = (title, body) => {
let notes = [];
let note = {
title,
body
};
notes.push(note);
fs.writeFileSync("notes-data.json", JSON.stringify(notes));
notes = JSON.parse(fs.readFileSync("notes-data.json"))
};
提前致谢
【问题讨论】: