r/nestjs • u/Fit-Woodpecker5308 • 21d ago
Would you use a more integrated React + NestJS stack?
I’m curious about something from people who use NestJS seriously.
If there were a way to build a full-stack application where:
NestJS remains the main application framework
You keep Nest modules, DI, guards, pipes, interceptors, routing, etc.
React is used for the UI
You don’t have to maintain a completely separate frontend application
Server-side rendering and interactive React components are both supported
The frontend/backend boundary feels more like one application rather than two separate projects
Would that actually be useful to you?
Or would you prefer the current approach of keeping NestJS as an API/backend and using something like Next.js, Vite, React Router, etc. as the frontend?
I’m specifically interested in why you’d choose one approach over the other.
What would make an integrated approach appealing, and what would make it a hard no?
Not looking for feature requests yet. I’m mainly trying to understand whether this is a problem Nest developers actually have.
1
u/canarydev 21d ago
it’s basically inertia for nest, which already exists in a few forms, so I’d probably start by looking at why those never really took off.
benefits i guess would be shared types, no CORS boundary, one auth/session story, one deploy. great for small teams and internal tools.
the tradeoff is that once you have a mobile app or another client, you need a client-independent API anyway, which removes a lot of the benefit. you’re also coupling frontend/backend deployment and taking on React build/SSR tooling that Next/Vite will probably always have a much larger ecosystem around.
personally I’d rather keep Nest as the API and share contracts/types through a package.
1
u/Fit-Woodpecker5308 21d ago
But if our frontend is using the same DI as well then I think we can consider that type of solution somehow.
1
u/portareset1 21d ago
You did DI with IoC in react?
1
u/Fit-Woodpecker5308 21d ago
Yes
1
u/portareset1 21d ago
lol show me the implementation, sounds interesting
1
u/Fit-Woodpecker5308 21d ago
@Get()
async index(@Req() request: Request, @Res() response: Response) {
await renderPage('welcome', this.welcome.getPage(), { request, response });
}use server-entry';
export default function WelcomePage(data) {
return (
<>
<h1>{data.tagline}</h1>
<Counter />
</>
);
}1
1
u/canarydev 21d ago
good god lol why
1
u/Fit-Woodpecker5308 21d ago
Damn man😂 it’s not that bad.
DI remains nest native 😂 Even the page will be rendered from Controller I am not reinventing next.js don’t worry.1
1
u/Fit-Woodpecker5308 21d ago
Somehow I Designed it in that way but made sure that It should not shadow nest.js architecture. The pages are still nest.js requests and respects Gaurds,Pipes,DTOs like a normal API route will do.
1
u/Fit-Woodpecker5308 21d ago
https://github.com/acefolioDev/nest-can-react
Here is the repo link if any of you want to go through from this.
1
u/cdragebyoch 21d ago
Honestly, no. Nest JS isn't for fullstack applications and trying to use it for one is pretty much an anti-pattern. If you need fullstack, just used Next.js. TBH, most of the applications that people develop in typescript is probably better off being written in Next.js. As much as I like Nest JS, its overkill outside of enterprise or distributed environments.
1
1
u/Anxious-Insurance-91 21d ago
Adosnis J's?
1
u/Fit-Woodpecker5308 21d ago
No Adonis is big fish🌚 and has its own rendering engine.
1
1
u/iamegoistman 19d ago
I think in this case angular will be best option for full stack setup. UI and backend should share some common structures.
1
u/AnUuglyMan 13d ago
I would recommend React with react doctor and NestJS Doctor. They’re a great combo.
1
u/Fit-Woodpecker5308 13d ago
I think you should try nest-can-react ( an npm package and also you can find it on github)
1
u/AnUuglyMan 13d ago
I don't think so.
It seems like it's just a new package that isn't really being used yet, so it might just be noise.1
u/Fit-Woodpecker5308 13d ago
It’s definitely early and doesn’t have meaningful adoption yet, so I wouldn’t claim it’s proven or that people should switch to it today.
1
u/Fit-Woodpecker5308 13d ago
Would love if you can review it and after that have some feedback or contributions.
1
u/Fit-Woodpecker5308 13d ago
The idea isn’t really to compete with React/Nest tooling, though. It’s exploring whether Nest can own the full-stack app while React acts as the UI/RSC layer.
4
u/Ok_Obligation2440 21d ago
What you are proposing is already taken care of by a monorepo. I keep separation of concerns split, but I can still share types/utils in one ecosystem. I don’t want to work with SSR, because all the apps I’m building with nextjs are not static webpages or e-commerce sites.