Usage with Express
Example app
| Description | URL | Links | 
|---|---|---|
| Express server & procedure calls with Node.js. | n/a | 
How to add tRPC to existing Express project
1. Install deps
bash
bash
Zod isn't a required dependency, but it's used in the sample router below.
2. Create a tRPC router
Implement your tRPC router. A sample router is given below:
server.tsts
server.tsts
If your router file starts getting too big, split your router into several subrouters each implemented in its own file. Then merge them into a single root appRouter.
3. Use the Express adapter
tRPC includes an adapter for Express out of the box. This adapter lets you convert your tRPC router into an Express middleware.
server.tsts
server.tsts
Your endpoints are now available via HTTP!
| Endpoint | HTTP URI | 
|---|---|
| getUser | GET http://localhost:4000/trpc/getUser?input=INPUTwhere INPUTis a URI-encoded JSON string. | 
| createUser | POST http://localhost:4000/trpc/createUserwith req.bodyof type{name: string} |