A step-by-step guide to migrating a NestJS REST API to tRPC within a pnpm monorepo shared with a Next.js frontend. Covers replacing NestJS controllers with typed tRPC routers using nestjs-trpc, defining Zod input/output schemas, setting up per-request context, implementing protected middleware for auth, generating the AppRouter type via CLI, and wiring up the Next.js client with fully typed hooks. The key benefit demonstrated is compile-time detection of backend-to-frontend type mismatches, eliminating the need for manually maintained type definitions on the client.

8m read timeFrom telerik.com
Post cover image
Table of contents
PrerequisitesWhy Choose tRPC Over RESTProject SetupMonorepo FoundationBackend SetupCreating Our RouterProtected ProceduresGenerating the AppRouterFrontend SetupProving End-To-End Type SafetyConclusion
733 Impressions