espace-codage / server /src /routes /projects.store.ts
Abmacode12's picture
Architecture “Rosalinda” (100% propriétaire)
6ce9b06 verified
raw
history blame contribute delete
485 Bytes
```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");
}
```