import { Router } from 'express'; import { readFile } from 'fs/promises'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; const router = Router(); const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const DATA_PATH = join(__dirname, '..', 'data', 'notes.json'); router.get('/', async (req, res) => { try { const raw = await readFile(DATA_PATH, 'utf-8'); const notes = JSON.parse(raw); res.json(notes); } catch (err) { res.status(500).json({ error: 'Failed to load notes' }); } }); export default router;