MaLeK
MaLeK5mo ago

Express.JS and tRPC

guys kindly what are the differences between tRPC and express, I think they do the same work, isn't?
2 Replies
david
david5mo ago
@MaLeK In terms of communicating between a client and a server yes of course. But they definitely lean to different needs/use cases. The biggest thing being that if you have a tightly coupled frontend/backend both built in typescript in my opinion tRPC is a no brainer. Alternatively, say you needed to build an backend which links to other projects where the ownership isn't exactly under the same repo or your control then tRPC is going to be more difficult to implement and the disadvantages begin to increase versus the advantages, you'd arguably find a more customizable experience with something like to express. Express: - Web framework for building/managing HTTP-based applications. - A pretty robust/matured routing, middleware and way of structuring a server. - Most ideal for building traditional RESTful APIs and web servers, especially where you might be connecting to other applications in the future out of your direct ownership in the same project 🙂 . TRPC - A focus on typesafe API applications - Fantastic way to build shared API types between frontend and backends if you're already in the typescript especially in the same repo - Integrated utilities/nice-to-haves like formatted error handling, input validation and data fetching on the frontend It's not to say you cannot connect both express + trpc together, that's what Im doing at the moment with the express adapter, some endpoints are exposed not via tRPC for webhooks or to other applications that are out of our control. But for the ones that are, and which are in our monorepo it's a no brainer to use tRPC i've found. https://trpc.io/docs/server/adapters/express Could possibly help with various other things like exposing cookies/managing express middlewares
david
david5mo ago
Don't know if that's 100% accurate, perhaps Alex has some extra things to say or maybe im wrong with a few points, but that's how I see it from my perspective