Hey NestJS + tRPC community! π
Iβm excited to release nest-trpc-native v0.3.0 β a decorator-first, native-feeling tRPC integration for NestJS.
No adapter glue code in your app layer. No compromise on NestJS features.
You write tRPC routers like Nest classes, with full support for dependency injection, guards, interceptors, pipes, filters, request-scoped providers, and end-to-end type safety.
Why this matters
Most tRPC + NestJS approaches push you toward one side:
- Keep all NestJS lifecycle features, but lose clean tRPC developer experience, or
- Keep pure tRPC style, but lose NestJS enhancers and request-scoped DI.
nest-trpc-native is designed so you can have both.
Core Features
-
@Router('users')+@Query(),@Mutation(),@Subscription() - Full support for
@UseGuards(),@UseInterceptors(),@UsePipes(ValidationPipe),@UseFilters() -
@Input()and@TrpcContext()for parameter extraction - Auto-generated router types (
autoSchemaFile: 'src/@generated/server.ts') - Works with Express and Fastify
- Zod or classic
class-validatorvalidation - Zero runtime dependencies in
nest-trpc-nativeitself (host app controls Nest/tRPC peers) - Monorepo-friendly sample layout
- Microservice transport pattern demonstrated in a focused sample
Router Example (NestJS style)
@Router('users')
@UseGuards(AuthGuard)
export class UsersRouter {
constructor(private readonly usersService: UsersService) {}
@Query({ input: FindOneSchema, output: UserSchema.nullable() })
@UsePipes(new ValidationPipe({ transform: true }))
findOne(
@Input() input: { id: number },
@TrpcContext('requestId') requestId: string,
) {
return this.usersService.findById(input.id);
}
@Mutation({ input: CreateUserSchema, output: UserSchema })
create(@Input() input: { name: string; email: string }) {
return this.usersService.create(input);
}
}
Client side stays fully type-safe:
const user = await trpc.users.findOne.query({ id: 123 });
// autocomplete + compile-time safety
Installation
npm install nest-trpc-native @trpc/server
npm install @nestjs/common @nestjs/core reflect-metadata rxjs
# optional:
npm install zod
Then register the module:
TrpcModule.forRoot({
path: '/trpc',
autoSchemaFile: 'src/@generated/server.ts',
})
Samples You Can Run Now
-
sample/00-showcase: full integration baseline (guards, interceptors, pipes, filters, request scope, Express/Fastify, typed clients, subscriptions) -
sample/11-microservice-transport: tRPC edge gateway + Nest microservice transport (TCP)
From repo root:
npm run showcase
Docs, Repo, and NPM
Docs: https://rodrigobnogueira.github.io/nest-trpc-native/docs/introduction
Repo: https://github.com/rodrigobnogueira/nest-trpc-native
NPM: https://www.npmjs.com/package/nest-trpc-native
Try it, break it, open issues, and share feedback.
Thanks!


Top comments (0)