Express and Fastify
nest-trpc-native is adapter-agnostic. Your router code stays identical regardless of the underlying HTTP framework.
Express (Default)
main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();
Fastify
main-fastify.ts
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);
}
bootstrap();
No Router Changes Needed
The same router class works with both adapters:
@Router('cats')
class CatsRouter {
@Query()
list() {
return [{ id: '1', name: 'Whiskers' }];
}
}
Internally, the HTTP transport uses the tRPC Fetch adapter to normalize the request/response interface across frameworks.
Verifying Adapter Parity
The showcase includes smoke tests for both adapters:
npm run smoke:express
npm run smoke:fastify
Both run identical client requests against the server to confirm consistent behavior.