@nestjs/serve-static

Official NestJS module for serving static files and single-page apps from an Express or Fastify server

SDK
npm
v5.0.5
514stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
79/100Good
Development Activity100
Maintenance72
Community56
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture80
Code Quality78
Innovation58
Learning Curve90

@nestjs/serve-static is the official NestJS module for serving static assets — typically a built single-page application — directly from a Nest server without a separate web server or reverse proxy. It plugs into the existing Express or Fastify HTTP adapter that the Nest app already uses, so no extra runtime dependency is added beyond the adapter-specific static-file middleware.

The module detects which underlying HTTP adapter (Express or Fastify) the application is running on via an internal loader abstraction, and registers the appropriate static-serving middleware automatically. It supports serving multiple root paths, custom render paths, and excluding specific routes (such as API prefixes) from being intercepted by the static handler, configurable through both forRoot() and forRootAsync().

What You Get

  • ServeStaticModule.forRoot() and forRootAsync() for static or dependency-driven configuration
  • Automatic detection of the underlying HTTP adapter (Express or Fastify) with dedicated loader implementations for each
  • Support for multiple static root paths registered simultaneously
  • Route exclusion so API endpoints aren’t shadowed by the static file handler
  • A no-op loader fallback so the module degrades gracefully when no supported adapter is present

Common Use Cases

  • Serving a built React/Vue/Angular SPA bundle directly from the same NestJS server that exposes the app’s REST API
  • Deploying a full-stack app as a single process/container without a separate Nginx or static-hosting layer
  • Excluding /api (or similar) route prefixes from static file interception in combined frontend+backend deployments
  • Switching between Express and Fastify adapters without changing static-file-serving configuration

Under The Hood

Architecture ServeStaticModule (in lib/serve-static.module.ts) is a dynamic Nest module implementing OnModuleInit; on init it resolves the app’s HttpAdapterHost and delegates to an AbstractLoader implementation selected by serve-static.providers.tsExpressLoader, FastifyLoader, or a NoopLoader fallback when no recognized adapter is present — each loader registering the adapter-native static middleware with the module’s configured root paths and exclusions.

Tech Stack TypeScript module with @fastify/static, express, and fastify all declared as optional peer dependencies (only one is required at runtime depending on the app’s adapter), plus path-to-regexp as the sole hard runtime dependency for route-exclusion pattern matching. Testing uses Vitest with a full e2e suite under tests/e2e/ exercising both express-adapter.e2e-spec.ts and fastify-adapter.e2e-spec.ts against a real sample Nest app in tests/src/.

Code Quality Unlike some smaller official Nest modules, this repo carries genuine end-to-end tests: a sample controller/module/main.ts under tests/src/ is booted with supertest against both the Express and Fastify adapters to verify static files are actually served and routes are excluded correctly, rather than relying on unit tests of mocked internals alone. Source files remain small and single-purpose, consistent with other official @nestjs/* modules.

API Design The module follows NestJS’s now-familiar forRoot()/forRootAsync() dynamic-module convention, so existing Nest developers can configure it with zero new concepts — pass a root path (default client) and optional exclusion patterns. Adapter detection is fully automatic, meaning the same configuration code works whether the app runs on Express or Fastify, which removes an entire class of adapter-specific configuration that would otherwise fall on the developer.

Used by 8 apps in this directory

TypeScript
96%
Other

Amplication

Developer Tools · AI Code Assistants · Automation

16,010

Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.

View details
61
Repo Health
84
Technical
60
Dependency
Built with
TypeScript96%
Updated 1 months ago
TypeScript
97%
AGPL 3.0

Bigcapital

Invoicing Finance

3,846

Self-hostable double-entry accounting platform with invoicing, inventory, multi-currency, and real-time financial reporting for small and medium businesses.

View details
91
Repo Health
77
Technical
64
Dependency
Built with
TypeScript97%
Updated yesterday
TypeScript
74%
AGPL 3.0

Ghostfolio

Invoicing Finance

9,153

Track your stocks, ETFs, and crypto with a privacy-first, self-hostable wealth management platform built for data-driven investors.

View details
93
Repo Health
79
Technical
71
Dependency
Built with
TypeScript74%
HTML23%
Updated yesterday
TypeScript
98%
Other

Hexabot

AI Development · Automation

1,186

Build and run agentic workflows across channels with YAML, tools, and RAG

View details
79
Repo Health
76
Technical
70
Dependency
Built with
TypeScript98%
Updated yesterday
TypeScript
94%
AGPL 3.0

Laudspeaker

Marketing · Automation

2,618

Open-source customer engagement platform for building visual, event-triggered messaging journeys across email, SMS, push, in-app, and webhooks.

View details
53
Repo Health
66
Technical
64
Dependency
Built with
TypeScript94%
Updated 1 months ago
TypeScript
98%
Other

Novu

Developer Tools

39,615

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
65
Dependency
Built with
TypeScript98%
Updated today
JavaScript
59%
AGPL 3.0

ToolJet

Low Code Platforms · No Code Platforms · AI Agents

40,458

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
65
Dependency
Built with
JavaScript59%
TypeScript33%
Updated today
TypeScript
79%
Other

twenty

CRM

55,120

The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.

View details
92
Repo Health
82
Technical
67
Dependency
Built with
TypeScript79%
MDX17%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search