Build a REST API with Express 5 and Node.js
API with Express is an intermediate-level course of 5 lessons (about 3 h 26 min), with 15 exercises and 15 quiz questions. Prerequisites: Node.js Fundamentals, HTTP and REST APIs. Exercises run in the browser, with nothing to install.
- Server-side JavaScript
- Intermediate
- 5 lessons
- 3 h 26 min
- 15 exercises
- Exercises run in the browser
The course in brief
This course teaches you to design and code a professional REST API with Express 5, the reference web framework for Node.js. You will write routes, understand the middleware chain, validate incoming data, centralize error handling, and then structure a CRUD API in layers, with pagination and testability.
What you will be able to do
- Create an Express 5 application and define routes that read params, query, and body
- Write and order application-level, router-level, and route-level middleware
- Validate incoming data and return usable validation errors
- Centralize error handling by taking advantage of Express 5's promise support
- Structure a CRUD REST API in layers, with pagination and tests
Syllabus: 5 lessons
- Create an Express 5 application and define routes
- Read path parameters, query parameters, and the request body
- Return JSON responses with the right status code
- 02
Middleware: Express's Processing Chain
- Explain how the middleware chain and next() work
- Write application-level, router-level, and route-level middleware
- Order middleware correctly (body parsing, logging, authentication)
- 03
Validating Incoming Data
- Validate the body, parameters, and query string of a request
- Return clear validation errors the client can act on
- Write a reusable validation middleware and know the schema libraries
- 04
Handling Errors with Express 5
- Centralize error handling in a dedicated middleware
- Create business HTTP errors and translate them into consistent responses
- Use Express 5's native handling of rejected promises
- 05
Structuring a Complete CRUD REST API
- Design consistent REST routes for a resource
- Separate routes, controllers, services, and data access
- Add pagination and filtering, then test the API
REST designLayered architecturePaginationTesting Express APIs
Final project
Booking Management REST API
Design and code, with Express 5, the API of a time-slot booking service (meeting rooms, classes, appointments): `ressources` and `reservations` resources, full CRUD, validation of dates and overlaps (409 on conflict), pagination and filtering by date, API key authentication, a single error format, and a layered architecture with an injectable repository.
Deliverables
- The API code organized into app.js, server.js, routes, services, and repositories
- Route documentation (methods, parameters, responses, error codes), for example in OpenAPI or in the README
- Unit tests of the middleware and services, and integration tests with supertest
- A collection of requests (curl, HTTPie, or a REST client) demonstrating each case
Assessment criteria
- Routes follow REST conventions and use appropriate status codes
- All inputs are validated, with no mass assignment
- Errors follow a single format and disclose no internal details
- Business logic (overlaps) is isolated in the service layer and tested
- The application can be tested without a real database thanks to repository injection
Frequently asked questions
Does this course use Express 4 or Express 5?
Express 5, the current version installed by default. The important differences from Express 4 are pointed out to help you maintain existing code.
What are the prerequisites for this course?
The basics of Node.js (course JS1) and some notions of HTTP and APIs (course B1): methods, status codes, and JSON.
Does the course cover databases?
The course focuses on the HTTP layer and architecture. It uses an in-memory repository and shows how to replace it with a SQL repository without changing the routes.
How do you test an Express API?
By separating the creation of the application from the call to listen, you can test middleware in isolation with fake objects and the complete API with supertest or fetch.
This course, told for your job
Say what you want to be able to do: “API with Express” takes its place in your path, with examples from your field. The concepts stay those of the course.