Serveur minimal
import express from "express";
const app = express();
app.use(express.json());
app.use(express.static("public"));
app.get("/api/taches", (req, res) => res.json(taches));
app.get("/api/taches/:id", (req, res) => {
const t = taches.find((x) => x.id === Number(req.params.id));
t ? res.json(t) : res.status(404).json({ erreur: "introuvable" });
});
app.post("/api/taches", (req, res) => { /* valider, ajouter */ res.status(201).json(t); });
app.listen(3000);
Aller plus loin
- Valider toutes les entrées (bibliothèque zod).
- Stocker dans une base (SQLite, PostgreSQL).
- Gestion d'erreurs centralisée, journalisation.
- En production : derrière Nginx, lancé par systemd.
Concepts : API REST.