Node.jsQuestion 16 of 26
Express
Answer out loud or in your head first, then compare.
Answer
Express is an HTTP framework for Node. It provides routing and a middleware chain, which makes it easier to organise endpoints, validation and error handling.
JavaScript
import express from 'express';
const app = express();
app.use(express.json());
app.get('/health', (req, res) => res.json({ ok: true }));
app.use((error, req, res, next) => {
if (res.headersSent) return next(error);
console.error(error);
res.status(500).json({ error: 'Server error' });
});
app.listen(3000);To be precise: middleware order matters. An error handler takes four arguments. Express 5 passes rejected Promises from async handlers to error handling; the older Express 4 needs explicit handling.
How did it go? Be honest — “Not yet” puts the question on your review list.