()
| 30 | |
| 31 | // Load persisted data or seed with initial data |
| 32 | function loadData() { |
| 33 | try { |
| 34 | const raw = readFileSync(DATA_FILE, 'utf-8') |
| 35 | const todos: Array<Todo> = JSON.parse(raw) |
| 36 | todos.forEach((todo) => todosStore.set(todo.id, todo)) |
| 37 | console.log(`Loaded ${todos.length} todos from ${DATA_FILE}`) |
| 38 | } catch { |
| 39 | console.log(`No existing data file, starting empty`) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | function saveData() { |
| 44 | writeFileSync( |