New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@eviloma/nestjs-trpc

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eviloma/nestjs-trpc

<source media="(prefers-color-scheme: dark)" srcset="https://i.imgur.com/JvsOXCg.png" />

latest
Source
npmnpm
Version
2.0.0-canary.29
Version published
Maintainers
1
Created
Source
tRPC

Nestjs tRPC Adapter (TRPC 11 + Zod 4)

An opinionated approach to building
End-to-end typesafe APIs with tRPC within NestJS.

Fork with support TRPC 11 and Zod 4!

Demo

The client above is not importing any code from the server, only its type declarations.

Introduction

NestJS tRPC is a library designed to integrate the capabilities of tRPC into the NestJS framework. It aims to provide native support for decorators and implement an opinionated approach that aligns with NestJS conventions.

Features

  • ✅  Supports most tRPC features out of the box with more to come.
  • 🧙‍  Full static typesafety & autocompletion on the client, for inputs, outputs, and errors.
  • 🙀  Implements the Nestjs opinionated approach to how tRPC works.
  • ⚡️  Same client-side DX - We generate the AppRouter on the fly.
  • 🔋  Examples are available in the ./examples folder.
  • 📦  Out of the box support for Dependency Injection within the routes and procedures.
  • 👀  Native support for express, fastify, and zod with more drivers to come!

Quickstart

Installation

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

# npm
npm install @eviloma/trpc-nestjs zod @trpc/server

# pnpm
pnpm add @eviloma/trpc-nestjs zod @trpc/server

# yarn
yarn add @eviloma/trpc-nestjs zod @trpc/server

How to use

Here's a brief example demonstrating how to use the decorators available in NestJS tRPC:

// users.router.ts
import { Inject } from '@nestjs/common';
import { Router, Query, UseMiddlewares } from 'trpc-nestjs';
import { UserService } from './user.service';
import { ProtectedMiddleware } from './protected.middleware';
import { TRPCError } from '@trpc/server';
import { z } from 'zod';

const userSchema = z.object({
  name: z.string(),
  password: z.string()
})

@Router()
class UserRouter {
  constructor(
    @Inject(UserService) private readonly userService: UserService
  ) {}

  @UseMiddlewares(ProtectedMiddleware)
  @Query({ output: z.array(userSchema) })
  async getUsers() {
    try {
      return this.userService.getUsers();
    } catch (error: unknown) {
      throw new TRPCError({
        code: "INTERNAL_SERVER_ERROR",
        message: "An error has occured when trying to get users.",
        cause: error
      })
    }
  }
}

👉 See full documentation on NestJS-tRPC.io. 👈

This documentation for original nestjs-trpc, but you can use it with TRPC 11 and Zod 4.

All contributors

NestJS tRPC is developed by Kevin Edry, which taken a huge inspiration from both NestJS and tRPC inner workings.

A table of avatars from the project's contributors

Keywords

nestjs

FAQs

Package last updated on 17 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts