Docs
Installation

Installation

This document will guide you through the installation and setting up of NestJS tRPC in your nestjs project.

⚠️

If you don't have a NestJS project setup yet, please visit our NestJS Quickstart Guide or check out the official NestJS documentation.

Manual Installation

To install NestJS tRPC with your preferred package manager, you can use any of the following commands:

npm install nestjs-trpc

Initialization

Once the packages are installed, we can import the TRPCModule and configure it with the forRoot() static method.

app.module.ts
import { Module } from '@nestjs/common';
import { TRPCModule } from 'nestjs-trpc';
 
@Module({
  imports: [
    TRPCModule.forRoot({
      autoSchemaFile: './src/@generated',
    }),
  ],
})
export class AppModule {}

The forRoot() method takes an options object as an argument. These options are passed through to the underlying express or fastify driver. For example, if you want to disable the schema file generation (when deploying to production), you can omit the autoSchemaFile option.

Start your NestJS server. You should be good to go! 🎉

âś‹

When setting up NestJS tRPC you must set your "sourceMap": true in your compilerOptions within the tsconfig.json configuration file.

Module Options

You can import TRPCModuleOptions type from nestjs-trpc to safely assert all of the TRPCModule option types.

import { TRPCModule, TRPCModuleOptions } from 'nestjs-trpc';
const trpcOptions: TRPCModuleOptions = {
  autoSchemaFile: './src/@generated',
};
PropTypeDefault
basePath
string
"/trpc"
autoSchemaFile
string
-
schemaFileImports
Array<Function | Object | ZodAny>
-
context
TRPCContext
-
transformer
unknown
-
errorFormatter
(opts: { shape, error }) => {}
-