Spaces:
Paused
Paused
| 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 }; |