NestJS vs Next.js: Key Differences Explained
NestJS and Next.js are one syllable apart and share almost nothing else. Origins, architecture, request paths and the documented cost of running both.
Two frameworks whose names differ by one letter get confused constantly, and the confusion is not symmetrical. NestJS documents how to plug itself into a Next.js application, in its own docs, with a migration table. Next.js documents nothing about NestJS — the whole documentation index contains zero mentions of it. One project treats the other as a neighbour with a shared border; the other does not know the border exists.
Getting this comparison right matters more than it looks, because the two are pulled toward each other right now. Next.js keeps acquiring server-side surface — Route Handlers, Server Actions, Proxy, an --api project template. NestJS keeps acquiring things that live next to a frontend — schema contracts shared with forms, a first-party observability platform, an MCP server built out of its own providers. The temptation to call that convergence and pick a winner is strong, and mostly wrong.
Everything below is checked against primary sources: the two official documentation sets, the release notes, the git history of both repositories and the npm registry. Where a claim is my own reading rather than a vendor's statement, it says so.
The short version
| Question | Next.js | NestJS |
|---|---|---|
| What is it, officially? | "A React framework for building full-stack web applications" | A framework for Node.js server-side applications whose architecture is "heavily inspired by Angular" |
| What problem did it set out to solve | Server-rendering React, then bundling/routing/caching around it | Architecture for backend code: modules, dependency injection, layering |
| Unit of code | A route segment, rendered by React | A provider, registered in an IoC container |
| Where your logic lives | Components, Server Actions, Route Handlers | Services behind controllers |
| Backend it does not want to be | Says its own backend features "are not a full backend replacement" | Never claims to render your UI |
| Runtime | Node.js (minimum v20.9) plus a CDN/edge layer for Proxy | "Nest runs anywhere Node.js does" — and only Node.js |
| State model | Stateless per request; instance-local memory | Long-lived process with singleton providers |
| Current stable (2026-11-12) | 16.4.6, published 2026-11-09 | 12.4.2, published 2026-11-09 |
If you are building a React product, you use Next.js. You add NestJS when the part behind React needs to be a codebase someone else can own. The rest of this article is the evidence for those two sentences.
1. Two origins with no common ancestor
The dates are unambiguous, so let's get them on the table first.
| Next.js | NestJS | |
|---|---|---|
| Repository created | zeit/next.js, 2016-10-05 (now vercel/next.js) |
nestjs/nest, 2017-02-04 |
| Earliest commits I pulled | around 2016-10-10, authored by nkzawa |
2017-02-05, authored by kamil.mysliwiec |
| First npm record | next@1.0.0, 2016-10-25, maintainers nkzawa + rauchg |
@nestjs/core@1.0.2, 2017-05-14, and 2.0.0 the same afternoon |
| Homepage in that first release | github.com/zeit/next.js |
— |
| Stars today | 143,461 | 77,006 |
| License | MIT | MIT |
| Official one-liner (repo description) | "The React Framework" | "A progressive TypeScript framework for Node.js backends" |
Two footnotes worth having. The npm name next was already taken before Next.js existed — the registry still shows a 0.1.0 published in 2011 by an unrelated package (medikoo/node-ext), which is why Next.js's own npm history begins directly at 1.0.0. And NestJS's version numbering in May 2017 was chaotic in a way that tells you something about its age: 1.0.2 and 2.0.0 landed within about an hour of each other, so "v1" was never really a stable thing.
There is no shared ancestor to dig up. Next.js came out of the React server-rendering world and Zeit/Vercel's hosting business. NestJS came out of Angular's architecture vocabulary applied to Node. The docs say so plainly, in the paragraph that opens the Introduction:
"In recent years, thanks to Node.js, JavaScript has become the "lingua franca" of the web for both frontend and backend applications. This has given rise to projects like Angular, React, and Vue, which improve developer productivity and enable the creation of fast, testable, and extensible frontend applications. However, while plenty of excellent libraries, helpers, and tools exist for Node.js (and server-side JavaScript), none of them effectively solves the main problem of architecture."
"Nest provides an out-of-the-box application architecture that lets developers and teams create highly testable, scalable, loosely coupled, and maintainable applications. The architecture is heavily inspired by Angular."
So NestJS's origin story is explicitly not about the frontend. It is a complaint about backend code structure, made in 2017, using Angular's toolkit: decorators, modules, providers, dependency injection. Next.js's origin story, per its own docs, is the opposite direction:
"Next.js is a React framework for building full-stack web applications. You use React Components to build user interfaces, and Next.js for additional features and optimizations. It also automatically configures lower-level tools like bundlers and compilers."
The similarity that fools people is superficial: both are TypeScript-first, both run on Node, both ship a CLI, both have a config file at the root. The thing that actually determines how your code is organised — what the framework compiles around — is different in kind, not degree.
2. The centre of gravity: a container versus a render tree
This is the difference everything else follows from.
Next.js is built around a render tree. The unit it thinks in is a route segment that produces UI. Code you would call "backend" exists inside that tree, as a component that runs on the server, and it inherits the tree's rules: it re-runs on each render, it composes through JSX, it is transformed by directives ('use client', 'use server', 'use cache'), and it is bundled by a compiler the framework owns. Next.js deliberately does not have an opinion about layering, because layering is React's job and React is a UI library.
NestJS is built around a container. The unit it thinks in is a provider: a class instantiated once, wired into other classes by the framework, registered inside a @Module(). Everything else — HTTP routes, WebSocket gateways, GraphQL resolvers, queue consumers, microservice handlers — is a transport bolted onto that container. The docs say this directly under "platform agnosticism":
"The Overview section of the documentation primarily shows coding techniques using HTTP server frameworks (e.g., apps providing a REST API or an MVC-style server-side rendered app). However, all those building blocks can be used on top of different transport layers (microservices or WebSockets)."
Nest keeps its own dependencies honest about that choice. The minimum set for a hand-rolled project is @nestjs/core, @nestjs/common, rxjs, and reflect-metadata — the last one being what makes decorator-driven DI possible at all. RxJS is there because Nest's interceptors hand back observables.
The practical consequence shows up in how each framework treats a database connection. In Nest you inject a provider that owns it; the process holds it open, and the docs warn you about the alternative:
"Request-scoped providers affect application performance. Although Nest caches as much metadata as possible, it still has to create an instance of your class on each request, which slows down your average response time and overall benchmark results. Unless a provider must be request-scoped, we strongly recommend using the default singleton scope."
In Next.js, the framework has no place to put that object, and its hosting assumptions often make the singleton wrong. Next.js's own caveat list for Route Handlers is blunt about it:
"Some hosts deploy Route Handlers as lambda functions. This means:
- Route Handlers cannot share data between requests.
- The environment may not support writing to File System.
- Long-running handlers may be terminated due to timeouts.
- WebSockets won't work because the connection closes on timeout, or after the response is generated."
That single list explains more about the relationship between these two frameworks than any feature comparison does. One of them assumes a process that lives; the other assumes a function that finishes.
3. What a request actually passes through
Same HTTP request, two very different itineraries.
Next.js
The documented order is: proxy (renamed from middleware in Next.js 16) → the matched route → either a render or a Route Handler. Proxy is explicitly not a place to build a backend:
"The
middlewarefile convention is deprecated and has been renamed toproxy.""Proxy is meant to be invoked separately of your render code and in optimized cases deployed to your CDN for fast redirect/rewrite handling, you should not attempt relying on shared modules or globals."
"Starting with Next.js 16, Middleware is now called Proxy to better reflect its purpose. The functionality remains the same."
And the limitations section goes further:
"Proxy is not intended for slow data fetching. While Proxy can be helpful for optimistic checks such as permission-based redirects, it should not be used as a full session management or authorization solution."
"Directives such as
use cacheanduse serverhave no effect in Proxy, because Proxy does not apply directive transforms."
Read that last sentence again, because it is the architecture telling you where it ends. The mechanism Next.js uses to give server code its powers — directive transforms — does not run in Proxy. Your Proxy code and your Server Action code are compiled by different rules.
Data fetching itself lives in Server Components, and mutations in Server Actions, which the docs define in React's terms, not HTTP's:
"A Server Action is a React Server Function invoked through React's action mechanisms, such as
<form action>,<button formAction>, or a client-side transition."
Where you do want a real endpoint, you write a Route Handler, which is a Web API surface rather than a framework one:
// app/api/orders/[id]/route.ts
import { type NextRequest, NextResponse } from 'next/server'
export async function GET(request: NextRequest, { params }) {
const { id } = await params
if (!(await canRead(id))) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
}
return NextResponse.json(await loadOrder(id))
}
Supported methods are GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, and Next.js answers OPTIONS itself when you do not define it. Note the shape of that code: the permission check is a line of code inside the handler. Nothing stops a teammate from writing the next handler without it.
NestJS
Nest documents its pipeline as an ordered contract, and the sentence the docs use is exactly the one people argue about in code review:
"In general, a request flows through middleware, then guards, then interceptors, then pipes, and finally back through interceptors on the return path (as the response is generated)."
Ordering is specified per level, too: global middleware runs before module-bound middleware, and guards run "global → controller → route", with pipes additionally covering route parameters. Exception filters come last and, as the docs put it, "run only when an uncaught exception occurs". The same requirement expressed in Nest looks like this:
// src/orders/orders.controller.ts
@Controller('orders')
@UseGuards(AuthGuard, OwnershipGuard)
export class OrdersController {
constructor(private readonly orders: OrdersService) {}
@Get(':id')
findOne(@Param('id', { schema: orderIdSchema }) id: number) {
return this.orders.load(id)
}
}
@nestjs/authentication's global guard replaces the if (!(await canRead(id))) line, and it cannot be forgotten by the next person, because the guard is attached at controller or application level. The schema option is new in Nest 12: parameter decorators accept any Standard Schema validator (Zod, Valibot, ArkType), and a StandardSchemaValidationPipe enforces it.
The two snippets differ in something more than syntax. In Next, safety is a thing you remember to write. In Nest, safety is a thing the container wires in whether you remember or not.
4. Capability matrix, using only what each side documents
| Concern | Next.js (official docs) | NestJS (official docs) |
|---|---|---|
| Self-description | "A React framework for building full-stack web applications" | Framework for Node.js server-side apps; architecture "heavily inspired by Angular" |
| Structure | File-system routing under app/; no documented layering rules |
@Module() / @Controller() / @Injectable(), IoC container with module scope |
| Validation | Not a framework concern; you write checks in the handler | @Body({ schema }) + Standard Schema pipes; class-validator path still supported |
| Auth | Guides and helpers; checks live where you put them | Global guards, @CurrentUser(), @nestjs/authorization for roles |
| HTTP layer | Route Handlers on Web Request/Response |
Three adapters: Express (still the default), Fastify, Node |
| Recommended adapter | n/a | v12.3+: "we recommend the NodeAdapter"; in v13 "the NodeAdapter will become the default" |
| Documented throughput | none published | wrk, 100 connections, Node.js 24: ~50% more RPS on NodeAdapter than ExpressAdapter, ~5% more than FastifyAdapter; ~3% fewer than plain Fastify, ~5% more than Hono on Node |
| Background work | after(), cron routes, platform features |
@nestjs/schedule @Cron(), @nestjs/mail, first-class queue consumers |
| Long-lived connections | Documented as broken on lambda hosts | @nestjs/websockets, @nestjs/microservices |
| HTML rendering | React, including streaming and RSC | @Render() with template engines (MVC-style), not React |
| API description | Not a documented concern | @nestjs/swagger OpenAPI generation from the same schemas |
| Observability | Platform/Vercel product surface | @nestjs/observe SDK, hooked into the request lifecycle |
| Agents / MCP | Content negotiation for Markdown, llms.txt file convention |
@nestjs/mcp: "turns a Nest application into a Model Context Protocol (MCP) server, whose tools, resources and prompts are methods of your providers" |
| Minimum Node.js | 20.9 | v20.19+, or v22.12+ on the 22.x line; CLI generators need v22.22.3+, v24.15+ or v26+ |
| Runs on | Node servers, containers, edge/CDN for Proxy | "Nest runs anywhere Node.js does"; Deno is not documented, Bun appears only as a package manager |
The adapter row deserves a second look, because it is where a well-known piece of NestJS folklore just changed. For years Nest was "the framework that uses Express", then Fastify became the performance answer, and now the docs recommend a third option built on node:http — with Express-style helpers on the request and response objects, so most Express middleware keeps working — and announce it as the default in v13. NestJS also ships as ESM packages since 12, while explicitly leaving CommonJS apps alone: "Existing CommonJS applications keep working — migrating your own code to ESM is entirely optional."
Next.js has its own version of that kind of quiet reversal in middleware.ts → proxy.ts. Both renames are worth reading as intent, not cosmetics: Next.js renamed a hook to make clear it is not your application layer, while NestJS is standardising on the runtime that needs neither adapter.
5. Where the two officially overlap
This is the part most comparisons skip, and it is the part with actual documentation behind it.
Next.js states its own ceiling. From the "Backend for Frontend" guide:
"Next.js backend capabilities are not a full backend replacement. They serve as an API layer that:
- is publicly reachable
- handles any HTTP request
- can return any content type"
and in the same guide, two caveats that read like warnings against a common mistake:
"Fetch data in Server Components directly from its source, not via Route Handlers. For Server Components prerendered at build time, using Route Handlers will fail the build step. This is because, while building there is no server listening for these requests."
"[Server Actions] are queued. Using them for data fetching introduces sequential execution."
NestJS then quotes that sentence back at you, in a recipe titled Next.js, whose opening paragraph is the clearest statement of the division of labour available anywhere:
"Route handlers and Server Actions are enough for a small backend. As it grows, with background jobs, webhooks, a public API, a mobile client or a team of its own, it needs the structure that Nest gives it: modules, dependency injection, guards, and validation on every route. Next.js keeps rendering, and Nest takes over everything behind it."
followed by a table:
| Next.js | Nest |
|---|---|
| Pages, layouts and Server Components | The API, and the business rules behind it |
| Forms, and the state of the browser | Validating what the forms send |
| Fetching data to render it | The database, and every other data source |
| Sign-in, permissions, webhooks, queues, scheduled jobs | |
| Other clients, such as a mobile app |
Notice that the right column keeps filling after the left one stops. That is the honest version of "vs" for these two: they are not two candidates for one job, they are two halves of a stack that stops overlapping around the point where a backend acquires its own clients.
So when is NestJS the wrong call? My own reading, not a vendor's: when your server code is only ever consumed by your own React components, a separate Nest process buys you a network hop and a second deployment for nothing. When you have one API key and a Supabase client, "backend" is a directory, not a system. Nest's own trigger words in that quote are the useful test — background jobs, webhooks, a public API, a mobile client, a team of its own. Any two of those and the split starts paying for itself.
6. Stitching them together, and the four seams that leak
The recipe's structure is a monorepo: apps/web (Next.js) and apps/api (Nest), browser talking only to the Next.js origin, and Next.js rewrites() forwarding /api onward. Cookies then work across both without CORS, because as far as the browser knows there is one server.
Getting that far is easy. Four things leak on the way, all documented.
One: rewrites are read at build time. The docs' warning is exact: "Next.js reads rewrites() when it builds the application, so API_URL must also be set for next build: a different value when the application starts doesn't change where its rewrites go." Choose fallback rather than afterFiles too: "fallback rewrites run after Next.js has checked all of its pages and route handlers, dynamic ones included", so a route handler you have not deleted yet keeps answering its own traffic.
Two: two hard ceilings, and they fail quietly. From the recipe: "Two limits fail badly, with a 500 and no useful error: a request body over 10 MB, and a response that takes more than 30 seconds to start, such as a call to a language model." Both can be raised through Next.js experimental options, but nothing tells you at runtime that you hit them.
Three: Nest loses sight of the visitor. "Nest also sees the Next.js server as the client, so req.ip is its address, and anything that limits requests per IP address, such as @nestjs/throttler, treats all your visitors as one." Next.js does not add X-Forwarded-For on its own; if a load balancer in front of it does, you call app.set('trust proxy', 1), and if it does not, you deliberately leave that off, "or a visitor can claim any address."
Four: same-origin stops being true inside the server. Session protection in @nestjs/authentication assumes the origin it is served from matches the origin it sees in requests. Behind a rewrite it does not: "Nest's own host is localhost:3001 while the browser's Origin is http://localhost:3000", so you name the Next.js origin as trusted. And when Server Components or Server Actions call Nest directly — which they can, since they run on the Next.js server — "the browser's cookies don't go with those requests unless you forward them", which the recipe handles with one small helper.
The pattern that makes all of this bearable is the one Nest 12 was built around: put your schemas in a package of their own.
packages/contracts/ # Zod / Valibot / ArkType schemas, one source of truth
apps/api/ # Nest: @Body({ schema: createUserSchema })
apps/web/ # Next: the same schema validates the form before it posts
"Put the schemas in a package of their own,
packages/contracts, and the Next.js app validates its forms with the very schema that Nest checks the request against, and both use the types inferred from it."
That is the real unification story: not one framework swallowing the other, but a shared contract package that makes the boundary cheap to cross. Nest's own migration table shows how mechanical the crossing is once you have it — a route handler becomes a controller method, getSession() at the top of every handler becomes a global guard plus @CurrentUser(), hand-written request.json() checks become @Body({ schema }), a webhook handler that reads request.text() becomes @VerifyWebhook(), a cron route called by your platform becomes @Cron(), and "work started with after(), such as sending email" becomes a queue plus @nestjs/mail.
7. Convergence: what each side is walking toward
Both projects are moving, and the directions are visible in what they shipped this year rather than in what anyone said.
Next.js is walking toward the server. create-next-app has an --api flag that scaffolds an example route.ts. The Backend for Frontend guide now covers content negotiation — serving Markdown to AI agents and HTML to browsers from the same URL, with Vary: Accept — plus file conventions for llms.txt, rss.xml and .well-known, rate limiting, webhooks and authentication guides. after() exists so you can schedule work past the response. proxy.ts replaced middleware. None of this is a claim to be a backend framework; each piece is Next.js refusing to be the reason you leave.
NestJS is walking toward whatever talks to it. Version 12, released 2026-08-27, is the tell: ESM packages, Standard Schema everywhere, a rebuilt CLI, and @nestjs/observe as first-party observability. The observability angle matters for this comparison, because it is explicitly not an HTTP middleware story: "Because the @nestjs/observe SDK hooks into Nest's own request lifecycle rather than wrapping the HTTP server, every measurement is labeled with the route pattern you declared (GET /cats/:id, not 10,000 distinct URLs)." A framework that can promise that has decided its container, not its transport, is the product. And @nestjs/mcp turns that container inside out: your providers' methods become tools, resources and prompts for an MCP client. So does the AI docs section, which covers agents, tools, models, embeddings and workflows.
Put those two arrows next to each other and the question "will they merge?" answers itself. Next.js's next moves are all about serving more kinds of response from the render pipeline. Nest's are about describing and instrumenting more kinds of input to the container. They are converging on the boundary between them from opposite sides, and the boundary is the shared schema.
Which brings me to my own conclusions, clearly labelled as such.
8. My reads
One: the merge is not going to happen, and the reason is not technical. A framework's centre of gravity is decided by what it compiles and what it assumes about process lifetime. Next.js compiles React with directive transforms and assumes a request may be served by a fresh instance with no memory of the last one. NestJS instantiates a container once and keeps it alive, which is precisely the assumption serverless hosts violate. Neither of those can be absorbed by the other without becoming a different product, and each vendor's business depends on the shape it has. Vercel sells a platform whose value is that the render pipeline is invisible; NestJS sells structure for teams that own a backend.
Two: the strongest evidence against a merger is a documentation gap. NestJS has a Next.js recipe, with a migration table. Next.js has no NestJS page, and its docs index has no mention of the name at all — while Vercel's own frameworks directory does list Nest as something you can deploy (as a project of its own). A framework that intended to become the backend you keep would not describe its own features as "not a full backend replacement".
Three: NodeAdapter is the most under-read signal in either ecosystem. Nest 12.3 recommends it, v13 makes it the default, and it drops the requirement to bring Express or Fastify into the process — with the docs claiming about 50% more requests per second than the Express adapter and only about 3% fewer than plain Fastify, on a benchmark anyone can rerun (wrk, 100 connections, Node.js 24). Read together with ESM packages and Standard Schema, Nest is not adding features, it is removing dependencies. That is what a framework does when it is preparing to be embedded in someone else's stack — including, plausibly, a render pipeline it does not own.
Fourth: the seam is where the bugs will live, and it is already mapped. 10 MB bodies, 30-second first bytes, req.ip being your own proxy, Origin mismatch behind a rewrite, cookies not forwarded by Server Components, and CDN caches serving a URL without ever running the handler that checked the credential. If you adopt this architecture, budget for those five specifically; they are not hypotheticals, they are the documented failure list. The mitigation is the same in every case: one contract package, one place where auth is decided, and one owner for the rewrite config.
Fifth: for agents, the two are becoming interchangeable in a way nobody planned. Next.js will now serve Markdown to a model from the same URL a browser sees. Nest will expose your providers as MCP tools. Both are answers to the same new question — what does your system look like to something that is not a browser — and neither answer requires the other framework to disappear. If I had to name one thing likely to actually unify these stacks in the next two years, it is not a rendering model or an adapter, it is the contract layer: schemas that a form, a validator, a documentation generator and an agent all read.
9. Decision reference
| Situation | What I would do |
|---|---|
| React product, one team, no other clients | Next.js alone. Do not add a backend process to feel organised |
Next.js app whose /api folder has become the hardest-to-review code in the repo |
Split it into Nest behind a fallback rewrite, keep apps/web rendering |
| Public API, mobile clients, webhooks, queues, cron | Nest as the system of record; Next.js (or anything else) as one consumer |
Heavy after() / cron-route usage inside Next.js |
Move those to @nestjs/schedule and queues; the platform scheduler will not be your business layer |
| Need WebSockets or long-lived connections | Nest. Next.js documents WebSockets as not working on lambda hosts |
| Need one validation truth for forms and endpoints | Standard Schema in packages/contracts; @Body({ schema }) server-side, same schema in the form |
| Existing Nest backend, new marketing/product frontend | Next.js in front, rewrite /api, then fix trust proxy and the trusted-origin list before anything else |
| Want an MCP server for internal tooling | @nestjs/mcp over your existing providers, rather than a second service that duplicates them |
References:
- Next.js documentation — "What is Next.js?"
- Next.js Backend for Frontend guide
- Next.js Server Actions guide
- Next.js Proxy (getting started)
- Next.js
proxy.jsfile convention - Next.js
route.jsfile convention - Next.js Self-Hosting guide
- Next.js Installation (minimum Node.js)
- NestJS Introduction and architecture
- NestJS Request lifecycle
- NestJS HTTP performance and adapters
- NestJS vs Fastify, Express and Hono
- NestJS recipe: Next.js
- NestJS platform agnosticism
- NestJS versions and Node.js support
- NestJS v12 migration guide
- NestJS MCP overview
- NestJS Observability overview
- NestJS v12.0.0 release notes
- Vercel frameworks directory: Nest
- npm registry:
nextpublish history - npm registry:
@nestjs/corepublish history