const express = require('express'); const cors = require('cors'); const port = 3001; const app = express(); app.use(express.json()); app.use(cors("*")); app.get("/test", async (req, res) => { res.send("Hello World!"); }); const tasks = [ { id: 1, completed: false, title: "Buy groceries for the week", description: "Pick up vegetables, fruits, milk, eggs, and bread from the supermarket.", dueDate: "14/03/2026", dateCreated: new Date(Date.now()).toLocaleDateString("en-AU") }, { id: 2, completed: false, title: "Clean the apartment", description: "Vacuum the floors, wipe kitchen surfaces, and take out the trash.", dueDate: "16/03/2026", dateCreated: new Date(Date.now()).toLocaleDateString("en-AU") }, { id: 3, completed: false, title: "Call the dentist for appointment", description: "Book a routine checkup and confirm available time slots for next week.", dueDate: "17/03/2026", dateCreated: new Date(Date.now()).toLocaleDateString("en-AU") }, { id: 4, completed: true, title: "Do laundry and fold clothes", description: "Wash dark and light loads separately, then fold and organize clean clothes.", dueDate: "21/03/2026", dateCreated: new Date(Date.now()).toLocaleDateString("en-AU") } ]; app.get("/api/tasks", async (req, res) => { try { res.json(tasks); } catch (error) { console.error(`Error: ${error}`) res.status(500).json({ message: "Error getting tasks" }) } }); app.post("/api/tasks/todo", async (req, res) => { try { const { title, description, dueDate } = req.body; const newTask = { id: tasks.length + 1, completed: false, title, title, description, description, dueDate, dueDate, dateCreated: new Date(Date.now()).toLocaleDateString("en-AU"), }; tasks.push(newTask); res.json(newTask); res.status(201).json(newTask); } catch (error) { console.error(`Error: ${error}`) res.status(500).json({ message: "Error creating task" }) } }); app.listen(port, () => { console.log(`To Do App listening on port ${port}`); });