
Product
Introducing PHP and Composer Support in Socket
Socket now supports PHP with full Composer and Packagist integration, enabling developers to search packages, generate SBOMs, and protect their PHP dependencies from supply chain threats.
@nestjs/serve-static
Advanced tools
A progressive Node.js framework for building efficient and scalable server-side applications.
@nestjs/serve-static package for Nest, useful to serve static content like Single Page Applications (SPA). However, if you are building MVC application or want to serve assets files (images, docs), use the useStaticAssets() method (read more here) instead.
$ npm i --save @nestjs/serve-static
See full example here.
Simply import ServeStaticModule in your Nest application.
import { Module } from '@nestjs/common';
import { join } from 'path';
import { ServeStaticModule } from '@nestjs/serve-static';
@Module({
imports: [
ServeStaticModule.forRoot({
rootPath: join(__dirname, '..', 'client')
})
]
})
export class ApplicationModule {}
The forRoot() method takes an options object with a few useful properties.
| Property | Type | Description |
|---|---|---|
rootPath | string | Static files root directory. Default: "client" |
serveRoot | string | Root path under which static app will be served. Default: "" |
renderPath | string / RegExp | Path to render static app (concatenated with the serveRoot value). Default: * (wildcard - all paths). Note: RegExp is not supported by the @nestjs/platform-fastify. |
exclude | string[] | Paths to exclude when serving the static app. WARNING! Not supported by fastify. If you use fastify, you can exclude routes using regexp (set the renderPath to a regular expression) instead. |
serveStaticOptions | Object | Serve static options (static files) |
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
Nest is MIT licensed.
The 'express-static' middleware is used in Express.js applications to serve static files. It is similar to @nestjs/serve-static but is designed for use with Express.js rather than NestJS. It provides similar functionality for serving static assets.
The 'koa-static' middleware is used in Koa.js applications to serve static files. Like @nestjs/serve-static, it allows you to serve static assets, but it is designed for use with the Koa.js framework.
The 'fastify-static' plugin is used in Fastify applications to serve static files. It provides similar functionality to @nestjs/serve-static but is tailored for the Fastify framework, offering high performance and low overhead.
FAQs
Nest - modern, fast, powerful node.js web framework (@serve-static)
The npm package @nestjs/serve-static receives a total of 359,655 weekly downloads. As such, @nestjs/serve-static popularity was classified as popular.
We found that @nestjs/serve-static demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports PHP with full Composer and Packagist integration, enabling developers to search packages, generate SBOMs, and protect their PHP dependencies from supply chain threats.

Security News
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.

Research
/Security News
Chrome extension CL Suite by @CLMasters neutralizes 2FA for Facebook and Meta Business accounts while exfiltrating Business Manager contact and analytics data.