HTTP Platform: Express, Fastify & HTTP Adapter
HTTP Platform: Express, Fastify & HTTP Adapter
NestJS abstracts over the HTTP platform while still letting you choose the underlying server. Express is the default and has the broadest middleware ecosystem; Fastify can provide stronger throughput when its plugin model fits your application.
Core idea
This feature is about controlling how the application is organized and how it behaves at runtime. These are the points a developer should understand before using it in a real project:
- The HTTP adapter is the bridge between NestJS and the underlying server framework.
- Express middleware usually works with app.use(), while Fastify prefers registered plugins.
- Inject HttpAdapterHost when infrastructure code needs adapter-safe access to the platform instance.
- Do not mix Express-specific response handling with framework-neutral code unless you accept the portability cost.
- Fastify requires Fastify-compatible plugins for cookies, CORS, multipart uploads, and compression.
Practical example
The following example shows the idea in a practical NestJS project. The goal is not to memorize the snippet, but to understand where it belongs in the architecture:
Production checklist
- Use framework-neutral return values from controllers whenever possible.
- Centralize adapter-specific setup in main.ts or infrastructure modules.
- Verify third-party middleware supports the chosen platform.
- Load test before switching platforms only for theoretical performance.
Summary
This lesson covers an advanced NestJS area that matters when building enterprise applications. Focus on clear boundaries, testable behavior, and choosing the right tool for the context instead of using every feature everywhere.