Spaces:
Paused
Paused
File size: 494 Bytes
210f2be | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | const fs = require("fs");
const path = require("path");
const base = path.join(__dirname, "../data");
function read(file) {
const filePath = path.join(base, file);
if (!fs.existsSync(filePath)) return [];
return JSON.parse(fs.readFileSync(filePath));
}
function write(file, data) {
const filePath = path.join(base, file);
const temp = filePath + ".tmp";
fs.writeFileSync(temp, JSON.stringify(data, null, 2));
fs.renameSync(temp, filePath);
}
module.exports = { read, write }; |