Spaces:
Configuration error
Configuration error
| ```typescript | |
| import fs from "fs"; | |
| import path from "path"; | |
| const dbPath = path.resolve("src/storage/projects.json"); | |
| export type ProjectDB = { projects: { id: string; name: string; createdAt: number }[] }; | |
| export function readProjects(): ProjectDB { | |
| if (!fs.existsSync(dbPath)) return { projects: [] }; | |
| return JSON.parse(fs.readFileSync(dbPath, "utf-8")); | |
| } | |
| export function writeProjects(db: ProjectDB) { | |
| fs.writeFileSync(dbPath, JSON.stringify(db, null, 2), "utf-8"); | |
| } | |
| ``` |