Files
diploma_todoapp/backend/index.js
2026-03-26 17:44:48 +08:00

63 lines
1.6 KiB
JavaScript

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.listen(port, () => {
console.log(`To Do App listening on port ${port}`);
});