# Building APIs with Express

> Build a typed REST API with Express: routing, middleware, a layered structure and centralised error handling. Free notes, key concepts, resources and a mini...

Canonical: https://www.internhack.in/roadmaps/tracks/full-stack/express
Last updated: 2026-11-28

Build a typed REST API with Express: routing, middleware, a layered structure and centralised error handling.

Intermediate · about 10 hours · difficulty 3/5

Learn first: [Node.js Runtime Essentials](https://www.internhack.in/roadmaps/tracks/full-stack/nodejs-runtime), [REST API Design](https://www.internhack.in/roadmaps/tracks/full-stack/rest-api-design)

**Express** is the most widely used Node.js web framework. It is minimal, so learning it teaches you what every backend framework does under the hood. Express 5 handles rejected promises from async handlers, which removes a classic source of crashes.

### Core concepts

- **Routing**: app.get, router.post and route parameters like /companies/:id.
- **Middleware**: functions that run in order for each request. Use them for JSON parsing, CORS, logging, auth and rate limiting.
- **Error middleware**: one handler with four arguments at the end of the chain turns thrown errors into consistent JSON responses.

### Structure that scales

Split code into **routes** (HTTP only), **controllers or handlers** (parse input, call services), **services** (business logic) and **data access** (Prisma or Drizzle). Group by feature (students/, companies/) rather than by type once the app grows.

### Must-have middleware

- express.json with a body size limit.
- cors configured for your actual frontend origin.
- helmet for security headers.
- A rate limiter on login and signup routes.

### Pitfalls

- Business logic and SQL inside route files, making everything hard to test.
- Sending a response twice (forgetting to return after res.json).
- CORS set to allow every origin with credentials.

You are ready to move on when you have an Express + TypeScript API for students and companies with feature folders, validation middleware, central error handling and security middleware.

## Key concepts

- **Routing and route params**
- **Middleware chain**
- **Error-handling middleware**
- **Layered structure: routes, services, data**
- **cors and helmet**
- **Rate limiting**
- **Express 5 async errors**

## Other options for this step

- [Building APIs with Fastify](https://www.internhack.in/roadmaps/tracks/full-stack/fastify): Build fast, schema-driven Node.js APIs with Fastify's plugin system, built-in validation and structured logging.
- [API Routes with Next.js Route Handlers](https://www.internhack.in/roadmaps/tracks/full-stack/next-route-handlers): Keep frontend and backend in one Next.js project by writing HTTP endpoints as route handlers, and know when a separate server is better.

## Mini project

Build an Express + TypeScript API for the placement portal with CRUD for companies and openings, Zod validation middleware, a central error handler, helmet, CORS and rate limiting on auth routes.

## Check yourself

Where in the middleware order should authentication run relative to body parsing and your route handlers, and why?

## Free resources

- [Express](https://expressjs.com/) (Express)
- [Express Guide: Routing](https://expressjs.com/en/guide/routing.html) (Express)
- [Full Stack Open](https://fullstackopen.com/en/) (University of Helsinki)

Previous: [REST API Design](https://www.internhack.in/roadmaps/tracks/full-stack/rest-api-design) · Next: [Building APIs with Fastify](https://www.internhack.in/roadmaps/tracks/full-stack/fastify)

## More in Node.js and API Design

- [Node.js Runtime Essentials](https://www.internhack.in/roadmaps/tracks/full-stack/nodejs-runtime)
- [REST API Design](https://www.internhack.in/roadmaps/tracks/full-stack/rest-api-design)
- [Building APIs with Express](https://www.internhack.in/roadmaps/tracks/full-stack/express)
- [Building APIs with Fastify](https://www.internhack.in/roadmaps/tracks/full-stack/fastify)
- [API Routes with Next.js Route Handlers](https://www.internhack.in/roadmaps/tracks/full-stack/next-route-handlers)
- [Error Handling, Validation and API Hardening](https://www.internhack.in/roadmaps/tracks/full-stack/api-errors-and-validation)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Full-Stack Developer Roadmap](https://www.internhack.in/roadmaps/tracks/full-stack)
