Backend
Express
Route requests, parse JSON and handle errors in Express 5.
Application
import express from 'express';Import Express in an ES moduleconst app = express();Create an applicationapp.use(express.json({ limit: '1mb' }));Parse JSON with a bounded body sizeapp.listen(3000);Start an HTTP listenerRouting
app.get('/health', (req, res) => res.json({ ok: true }));Send a JSON responsereq.params.idRead a named route parameterreq.query.pageRead query input; validate its type before useres.status(201).json({ id: 1 });Set status and send JSONMiddleware and errors
app.use('/api', router);Mount a router at a pathres.set('Cache-Control', 'no-store');Prevent caching a responsenext(error);Pass an error to error-handling middlewareapp.use((err, req, res, next) => res.status(500).json({ error: 'Unexpected error' }));Register four-argument error middleware after routes