()
| 245 | |
| 246 | // Ensure the data directory and file exist |
| 247 | async function initDataFile() { |
| 248 | try { |
| 249 | await fs.access(DATA_DIR); |
| 250 | } catch { |
| 251 | await fs.mkdir(DATA_DIR); |
| 252 | } |
| 253 | |
| 254 | try { |
| 255 | await fs.access(DATA_FILE); |
| 256 | } catch { |
| 257 | await fs.writeFile(DATA_FILE, JSON.stringify({})); |
| 258 | } |
| 259 | |
| 260 | console.log('Todo list stored at:', DATA_FILE); |
| 261 | } |
| 262 | |
| 263 | // Protected API routes |
| 264 | app.get('/api/todos', async (req, res) => { |