NestJS — Enterprise Node.js

HTTP Platform: Express, Fastify & HTTP Adapter

18 min Lesson 55 of 80

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:

async function bootstrap() { const app = await NestFactory.create<NestFastifyApplication>( AppModule, new FastifyAdapter({ logger: true }), ); await app.register(fastifyCookie); await app.listen({ port: 3000, host: '0.0.0.0' }); }
Design note: Choose the platform early. You can migrate later, but direct use of @Res(), Express middleware, or platform-specific plugins creates work during the switch.

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.
Rule of thumb: If the feature makes boundaries clearer and tests easier, it is probably the right choice. If it hides dependencies or makes tracing harder, redesign.

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.