Typed Middleware and Error Handlers
Write type-safe Express middleware functions.
Welcome
Type-safe Express middleware and error handlers prevent common bugs in request handling pipelines.
Middleware Signature
A middleware function takes req, res, next. Use the RequestHandler type from express.
import { RequestHandler } from 'express';
const authMiddleware: RequestHandler = (req, res, next) => {
if (!req.headers.authorization) return res.status(401).json({});
next();
};All lessons in this course
- Setting Up TypeScript with Node.js
- Typing Express Request and Response
- Typed Middleware and Error Handlers
- Environment Variables and Config Typing