npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

trpc-nuxt-module

v4.3.3

Published

tRPC for Nuxt — a Nuxt module that registers your router's HTTP and WebSocket handlers, fetches through the request event during SSR, and decorates the typed client with useQuery, useMutation and useSubscription over useAsyncData.

Readme

trpc-nuxt-module

Apache-2.0 licensed NPM version NPM downloads NPM Unpacked Size (with version)

tRPC for Nuxt. A Nuxt module that registers your router's HTTP handler — and, when you ask for it, a WebSocket handler over Nitro's own WebSockets — fetches through the request event during server rendering so a call never leaves the process, and decorates the typed client with useQuery, useLazyQuery, useMutation and useSubscription, each a composable over Nuxt's own useAsyncData.

Table of Contents


🚀 Getting Started

pnpm i trpc-nuxt-module @trpc/server @trpc/client

Register the module with the file and export name of your router and your context factory:

// nuxt.config.ts
export default defineNuxtConfig({
  modules: ["trpc-nuxt-module"],
  trpc: {
    createContext: { from: "~~/server/trpc/context", name: "createContext" },
    endpoint: "/api/trpc",
    router: { from: "~~/server/trpc/router", name: "appRouter" },
    // Optional: tRPC's WebSocket handler at this route, for subscriptions over `wsLink`
    webSocket: { endpoint: "/api/trpc/ws" },
  },
});
// server/trpc/router.ts
import { initTRPC } from "@trpc/server";
import { z } from "zod";

const t = initTRPC.create();

export const appRouter = t.router({ greeting: t.procedure.input(z.string()).query(({ input }) => `Hello ${input}`) });

export type AppRouter = typeof appRouter;

Provide a client from a plugin — createTRPCNuxtClient and the links are auto-imported:

// app/plugins/trpc.ts
import type { AppRouter } from "~~/server/trpc/router";

export default defineNuxtPlugin(() => {
  const trpc = createTRPCNuxtClient<AppRouter>({ links: [httpBatchLink<AppRouter>({ url: "/api/trpc" })] });
  return { provide: { trpc } };
});

And call a procedure from a page:

<script setup lang="ts">
const { $trpc } = useNuxtApp();
const name = ref("world");
const { data } = await $trpc.greeting.useQuery(name);
</script>

<template>
  <p>{{ data }}</p>
</template>

📖 Documentation

We highly recommend you take a look at the documentation to level up. It covers the design and the upstream trpc-nuxt issues this module answers.

Key exports

| Export | Description | | -------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | | trpc-nuxt-module | The module — router, createContext, endpoint and webSocket options | | createTRPCNuxtClient | The typed client, every procedure decorated with useQuery, useLazyQuery, useMutation or useSubscription | | httpLink, httpBatchLink | tRPC's links, sending through the request event during server rendering | | getQueryKey, getMutationKey | The useAsyncData keys a procedure's data is cached under, for useNuxtData and refreshNuxtData | | trpc-nuxt-module/runtime/server/createTRPCEventHandler | The HTTP handler over tRPC's fetch adapter, for a Nitro app without Nuxt |

A WebSocket connection's open and close call the trpc-nuxt-module:webSocket:open and trpc-nuxt-module:webSocket:close Nitro runtime hooks with its context, typed off your router.

Commands

Run from packages/trpc-nuxt-module/:

pnpm build        # compile to dist/
pnpm test         # vitest watch mode (coverage is run from the repo root)
pnpm bench        # the event handler against tRPC's own fetch adapter
pnpm lint:fix     # auto-fix lint
pnpm typecheck    # type check

⚖️ License

This project is licensed under the Apache-2.0 license.