A TypeScript monorepo demonstrating tRPC with client and server packages using npm workspaces.
trpc-monorepo-npm/
├── package.json # Root workspace configuration
├── package-lock.json
├── tsconfig.base.json # Base TypeScript configuration
├── .nvmrc # Node.js version specification
├── packages/
│ ├── client/ # tRPC client package
│ │ ├── src/
│ │ │ └── index.ts # Client implementation
│ │ ├── dist/ # Compiled JavaScript output
│ │ ├── package.json
│ │ └── tsconfig.json
│ └── server/ # tRPC server package
│ ├── src/
│ │ ├── index.ts # Server entry point
│ │ ├── trpc.ts # tRPC configuration
│ │ └── routers/
│ │ └── _app.ts # API route definitions
│ ├── dist/ # Compiled JavaScript output
│ ├── package.json
│ └── tsconfig.json
└── tooling/
└── typescript/ # Shared TypeScript configuration
├── base.json
├── node24.json
└── package.json
- Type-safe APIs with tRPC
- Monorepo architecture with npm workspaces
- Shared TypeScript configuration
- Development workflow with hot reloading
- Node.js 24+ with ES modules
- Node.js 24.0.0 or higher
- npm 9.0.0 or higher
-
Clone the repository
git clone [email protected]:trpc/examples-npm-monorepo.git cd examples-npm-monorepo
-
Install dependencies
npm install
-
Build all packages
npm run build
npm run dev
npm run dev:server
npm run dev:client
npm run start
npm run start:server
npm run start:client
The tRPC server package containing:
- API route definitions
- tRPC server configuration
- Type-safe procedure definitions
The tRPC client package containing:
- Client-side tRPC configuration
- Type-safe API calls
- Integration with the server
Shared TypeScript configuration used across all packages.
npm run build
- Build all packagesnpm run dev
- Start both client and server in development modenpm run start
- Start both client and server in production mode
npm run build
- Compile TypeScript to JavaScriptnpm run dev
- Start development server with hot reloadnpm run start
- Start production server
npm run build
- Compile TypeScript to JavaScriptnpm run dev
- Start development client with hot reloadnpm run start
- Start production client
This monorepo uses npm workspaces to manage multiple packages. The workspace configuration is defined in the root package.json
:
{
"workspaces": ["packages/*", "tooling/*"]
}
This enables:
- Installing dependencies at the root level
- Running scripts across all packages
- Sharing dependencies between packages
- Maintaining consistent versions across the monorepo
- Fork the repository
- Create a feature branch
- Make your changes
- Test your changes with
npm run build
andnpm run dev
- Submit a pull request
MIT License - see the LICENSE file for details.