HTTP Platform — Express vs Fastify

Pick the Engine Underneath Nest

HTTP Platform — Express vs Fastify

Nest is platform-agnostic. By default it runs on Express, but you can swap to Fastify with a one-line change.

4 min read Level 2/5 #nestjs#platform#fastify
What you'll learn
  • Understand the platform abstraction
  • Switch a Nest app to Fastify
  • Know when the underlying platform leaks through

Nest doesn’t ship its own HTTP server. It wraps Express by default and can wrap Fastify if you prefer. Most of your code never notices, which is exactly the point of the abstraction.

The Default — Express

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(3000);
}
bootstrap();

That’s stock Express under the hood. Anything you’ve heard about Express middleware, ecosystem, and edge cases applies.

Swapping to Fastify

npm i @nestjs/platform-fastify fastify
import { NestFactory } from '@nestjs/core';
import {
  FastifyAdapter,
  NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter(),
  );
  await app.listen(3000, '0.0.0.0');
}
bootstrap();

That’s it. Controllers, services, decorators — none of it changes. Fastify is roughly two to three times faster at the HTTP layer, with lower memory use. The trade is a smaller middleware ecosystem.

Where the Platform Leaks Through

The abstraction is good but not perfect. If you reach for the raw request or response, you’re on the platform’s API:

import { Req, Res } from '@nestjs/common';
import type { Request, Response } from 'express'; // or fastify

@Get()
raw(@Req() req: Request, @Res() res: Response) {
  res.setHeader('x-custom', 'hi');
  res.json({ ok: true });
}

Three places it matters:

  1. Native middleware packages (helmet, compression) have separate builds or wrappers for Fastify.
  2. Body parsing — Fastify ships its own JSON parser, Express uses body-parser. Different config knobs.
  3. File uploads@nestjs/platform-express and @nestjs/platform-fastify each have their own Multer/file modules.

How to Choose

Stay on Express unless you have a measured reason to switch. The ecosystem is bigger and most tutorials assume it. Pick Fastify when latency or throughput is a real constraint and you’re prepared to keep an eye on which packages support it.

Routing With Decorators →