After i do one post, the second time i try it gives me this error.
My post trys to send a json file as response, after a file is edited, it works the first time, the second time i do a post without closing the server stops working. If i restart de server it works again.
app.post("/data3", upload.array("files"), uploadFiles);
function uploadFiles(req, res) {
fs.watchFile(
"./data/results.json",
{
bigint: false,
persistent: true,
interval: 4000,
},
(curr, prev) => {
console.log("nThe file was edited");
console.log("Previous Modified Time", prev.mtime);
console.log("Current Modified Time", curr.mtime);
res.json(fs.readFileSync("./data/results.json", "utf8"));
console.log(
"The contents of the current file are:",
fs.readFileSync("./data/results.json", "utf8")
);
}
);
}