Build HTTP APIs with routing, middleware, validation, controllers, and error handling.
Lessons
Add a catch-all route for unmatched paths.
Handling 404 Not Found is easiest to learn by reading the example, changing it, and observing the result.
import express from 'express';
const app = express();
app.get('/api/lessons', (req, res) => res.json({ lessons: [] }));
// Catch-all for unmatched routes - must come last
app.use((req, res) => {
res.status(404).json({ message: `Not found: ${req.method} ${req.originalUrl}` });
});
app.listen(3000);Practice the Handling 404 Not Found example in a small scratch file, then explain what changed and why.