Node.js Backend Frameworks (Fastify, NestJS, Hono)
Parent: Software Engineering Patterns · Published reference · snapshot 2026-09-08 · skill software-engineering-patterns/references/nodejs-backend-frameworks.md
↓ Facts as markdownall context files
Three post-Express Node.js/TypeScript backend frameworks. They share the HTTP-handler foundation captured in the express-patterns hub reference (middleware chains, routing, error handling, graceful sh
These notes link each claim to its source. Some citations identify archived research reports that are no longer hosted on this site. A published reference means the content is available; it does not certify independent review or accuracy.Read the editorial policy and follow the sources before relying on a claim.
Node.js Backend Frameworks: Fastify, NestJS, and Hono
- Three post-Express Node.js/TypeScript backend frameworks. They share the HTTP-handler foundation captured in the express-patterns hub reference (middleware chains, routing, error handling, graceful shutdown, security hardening) - read that first; this reference covers what each framework does differently. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#nodejs-backend-frameworks-fastify-nestjs-and-hono]
- > Full reference: ~/.claude/skills/software-engineering-patterns/references/nodejs-backend-frameworks.md. Cross-refs: Express baseline → express-patterns; API surface design → api-design-patterns; backend architecture → backend-patterns; auth flows → web-auth-patterns; Zod/TypeBox depth → zod-schema-validation; edge/Bun/Deno runtimes → programming-languages/javascript-runtimes-deno-bun-edge. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#nodejs-backend-frameworks-fastify-nestjs-and-hono]
The spectrum
- NestJS - heavyweight, opinionated architecture + DI container + enterprise modules (decorator/Angular-style). Node only; uses Express OR Fastify as the HTTP adapter; no edge runtimes. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#the-spectrum]
- Fastify - mid-weight, Express-like ergonomics + raw speed + built-in JSON-Schema validation/serialization; minimal opinions. Node only. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#the-spectrum]
- Hono - lightweight (~14KB), Web-Standards (Request/Response) based, edge-native, tight type inference. Runs on Cloudflare Workers, Deno, Bun, Lambda, Fastly, Node. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#the-spectrum]
Fastify
- Plugins + encapsulation context governs which decorators/hooks/schemas a route sees; child contexts are isolated. fastify-plugin (fp) breaks encapsulation on purpose - wrap shared capabilities (DB, auth decorator) so parent/siblings see them. "Decorator not defined on parent" = missing fp. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#fastify]
- Lifecycle hooks (all encapsulated except onClose): onRequest → preParsing → preValidation → preHandler → handler → preSerialization → onSend → onResponse. onError is read-only; change error responses via setErrorHandler(). [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#fastify]
- JSON Schema on a route validates input AND compiles response serialization (fast-json-stringify) - a big speed source. addSchema() registers reusable schemas (encapsulated). TypeBox + @fastify/type-provider-typebox = one schema is both runtime validator and TS type. Async custom validators must return {error}, not throw (thrown → unhandled rejection → crash). [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#fastify]
- Decorators: decorateRequest('x', {}) shares ONE object across requests - init null, assign in onRequest. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#fastify]
- Gotchas: returning undefined from async handler = "no response"; mixing return value + reply.send() discards the second; after async reply.send() do return reply; arrow-function handlers don't bind this. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#fastify]
NestJS
- Modules + hierarchical DI: providers encapsulated by default; exports is the public API; other modules access via imports. @Global() sparingly. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#nestjs]
- Providers + scopes: default singleton; Scope.REQUEST (per request, perf cost, bubbles up injection chain); Scope.TRANSIENT (per injection site). Custom providers: useClass/useValue/useFactory/useExisting. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#nestjs]
- Request pipeline (fixed order): Middleware → Guards → Interceptors(pre) → Pipes → Handler → Interceptors(post) → Exception Filters. Guards = authZ; Interceptors = wrap handler (RxJS, transform req/resp); Pipes = validate/transform input; Filters = shape error responses. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#nestjs]
- Dynamic modules (forRoot/forFeature → DynamicModule) for configurable infra. Circular deps → forwardRef() on both sides; treat as a smell, prefer refactor. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#nestjs]
- HTTP adapter: swap @nestjs/platform-express for @nestjs/platform-fastify for Fastify throughput under Nest's architecture. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#nestjs]
Hono
- Web-Standards core + Context c: built on WHATWG Request/Response → runs everywhere. Middleware is async (c, next) => {...} (Koa onion model), no separate req/res. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#hono]
- Routing + typed generics: default RegExpRouter is fastest on Workers. new Hono<{ Variables, Bindings }>() makes c.get('user') and c.env.DB typed end-to-end. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#hono]
- Validation + RPC: @hono/zod-validator (+ Valibot/Typia/ArkType) gives typed c.req.valid(). RPC mode: export app type, hc<typeof app>(url) infers paths/args/returns - type-safe client, no codegen. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#hono]
- Batteries: JWT, basic/bearer auth, CORS, CSRF, secure-headers, ETag, cache, compression, body-limit, IP restriction, timing, timeout, SSE, WebSockets, JSX SSR. Edge wins are mostly geography (Workers at nearest PoP) + low overhead. Recommended for Node→Bun migration. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#hono]
Choosing
- NestJS - enterprise architecture, 3+ team, long-lived backend, first-party modules, Angular/.NET background, edge not required. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#choosing]
- Fastify - standalone Node API, Express-shaped + faster + built-in validation, pick-your-own ORM/auth. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#choosing]
- Hono - Cloudflare Workers/Vercel Edge/Deno/Bun/Lambda, smallest/fastest/most-inferred, serverless/edge, Node→Bun. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#choosing]
- Express - max middleware ecosystem/familiarity, no strong perf/validation/edge need. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#choosing]
- NestJS + Fastify adapter = Nest architecture + Fastify speed. NestJS does NOT run on edge runtimes. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#choosing]
Sources
- Fastify docs (Encapsulation, Plugins, Hooks, Validation-and-Serialization, Decorators, Errors); Nearform Fastify plugin guide; Strapi Fastify APIs; NestJS docs (Modules, Circular dependency, Performance/Fastify); DeepWiki NestJS request pipeline; LogRocket circular deps; Hono docs (Concepts, RPC, Validation, Benchmarks, Stacks); Cloudflare Hono story; freeCodeCamp Hono; Encore NestJS-vs-Fastify-vs-Hono (2026); Better Stack Hono-vs-Fastify; HireNodeJS frameworks 2026. [archived source: https://llms-explorer.com/sources/mdb-context-hub/nodejs-backend-frameworks/#sources]
Where this helps
- Choosing a backend framework for a new Node.js/TypeScript service based on architecture and deployment target: NestJS for a 3+ person team building a long-lived enterprise backend, Fastify for a standalone API wanting Express-like ergonomics with built-in validation, Hono for anything that must run on Cloudflare Workers, Vercel Edge, Deno, Bun, or Lambda. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
- Migrating an app from Node to Bun or into an edge/serverless runtime, where Hono's Web-Standards Request/Response core is the framework explicitly recommended for that path. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
- Squeezing extra throughput out of a NestJS app without abandoning its DI architecture, by swapping the HTTP adapter from @nestjs/platform-express to @nestjs/platform-fastify. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
- Building a type-safe client/server pair without codegen, using Hono's RPC mode where hc<typeof app>(url) infers paths, args, and return types directly from the exported app type. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
Project ideas
- Build a Fastify API where a single TypeBox schema serves as both the runtime validator and the TypeScript type, using @fastify/type-provider-typebox to eliminate the usual schema/type duplication. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
- Build a NestJS module using Scope.REQUEST providers to carry per-request state, such as a tenant id or a request-scoped logger, through the DI graph, understanding that this scope bubbles up the injection chain and costs more than a singleton. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
- Build an edge-deployed API on Hono with typed Variables and Bindings generics so c.get(user) and c.env.DB are typed end-to-end without manual casting. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
- Build a shared plugin for a Fastify app using fastify-plugin to intentionally break route encapsulation and expose a DB or auth decorator to parent and sibling contexts. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
Antipatterns
- Returning both a value and calling reply.send() in the same Fastify handler: the second write is discarded, and forgetting to return reply after an async reply.send() leaves the handler in an ambiguous state. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
- Treating NestJS circular dependencies that need forwardRef() on both sides as a normal pattern instead of a smell: the framework supports it, but it should prompt a module-boundary refactor. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
- Choosing Hono for an app that needs NestJS-style enterprise architecture and DI, or choosing NestJS for a workload that must run on an edge runtime: NestJS does not run on edge runtimes at all. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
- Deciding a framework choice primarily on synthetic JSON throughput benchmarks, such as Hono at roughly 78k req/s vs Fastify at roughly 62k req/s: real apps are dominated by database and business-logic latency, not routing overhead. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
Known issues
- Fastify's decorateRequest shares one object across every request unless you initialize it to null and assign per-request in onRequest, so reusing a mutable default value is a subtle cross-request data leak. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
- Fastify async custom validators must return an error object rather than throw: a thrown error inside a validator becomes an unhandled rejection and crashes the process. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
- NestJS's Scope.REQUEST providers carry a real performance cost and bubble that cost up through the entire injection chain, not just the provider itself. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
- Arrow-function route handlers in Fastify don't bind this, which breaks any handler code relying on Fastify's instance-bound this context. [source] — AI-suggested, synthesized from this pack's existing facts — not extracted from a source document.
Children
- Fastify plugins and encapsulation context (frontier)
- Fastify lifecycle hooks (frontier)
- Fastify JSON Schema validation and serialization (TypeBox type-provider) (frontier)
- Fastify decorators and anti-patterns (frontier)
- NestJS modules and hierarchical DI (frontier)
- NestJS providers and scopes (frontier)
- NestJS request pipeline (Middleware/Guards/Interceptors/Pipes/Filters) (frontier)
- NestJS dynamic modules and forwardRef circular deps (frontier)
- NestJS Fastify adapter (frontier)
- Hono Context and Web-Standards core (frontier)
- Hono RegExpRouter and typed Variables/Bindings (frontier)
- Hono validation (@hono/zod-validator) and RPC mode (frontier)
- Hono edge runtimes (Cloudflare Workers/Deno/Bun/Lambda) (frontier)
- Fastify-vs-NestJS-vs-Hono framework selection (frontier)
Frontier under this node: Fastify JSON Schema validation and serialization (TypeBox type-provider), Fastify decorators and anti-patterns, Fastify lifecycle hooks, Fastify plugins and encapsulation context, Fastify-vs-NestJS-vs-Hono framework selection, Hono Context and Web-Standards core, Hono RegExpRouter and typed Variables/Bindings, Hono edge runtimes (Cloudflare Workers/Deno/Bun/Lambda), Hono validation (@hono/zod-validator) and RPC mode, NestJS Fastify adapter, NestJS dynamic modules and forwardRef circular deps, NestJS modules and hierarchical DI, NestJS providers and scopes, NestJS request pipeline (Middleware/Guards/Interceptors/Pipes/Filters)