or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

application-interface.mdexpress-adapter.mdfile-upload.mdindex.md
tile.json

tessl/npm-nestjs--platform-express

Express.js HTTP platform adapter for NestJS applications with comprehensive file upload capabilities

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@nestjs/platform-express@11.1.x

To install, run

npx @tessl/cli install tessl/npm-nestjs--platform-express@11.1.0

index.mddocs/

NestJS Platform Express

NestJS Platform Express is the Express.js HTTP platform adapter for NestJS applications. It provides comprehensive Express integration including HTTP request/response handling, static file serving, view rendering, CORS support, body parsing, and a complete file upload system powered by Multer.

Package Information

  • Package Name: @nestjs/platform-express
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @nestjs/platform-express

Core Imports

import { 
  ExpressAdapter, 
  NestExpressApplication,
  getBodyParserOptions 
} from '@nestjs/platform-express';

For file upload functionality:

import { 
  FileInterceptor, 
  FilesInterceptor, 
  FileFieldsInterceptor,
  MulterModule 
} from '@nestjs/platform-express';

CommonJS:

const { ExpressAdapter, NestExpressApplication } = require('@nestjs/platform-express');

Basic Usage

import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './app.module';

async function bootstrap() {
  // Create Express-based NestJS application
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  
  // Configure Express-specific features
  app.useStaticAssets('public');
  app.setBaseViewsDir('views');
  app.setViewEngine('hbs');
  app.enableCors();
  
  // Configure custom body parser
  app.useBodyParser('json', { limit: '50mb' });
  
  await app.listen(3000);
}
bootstrap();

Architecture

NestJS Platform Express is built around several key components:

  • ExpressAdapter: Core HTTP adapter extending NestJS's AbstractHttpAdapter with Express-specific implementations
  • NestExpressApplication: Enhanced application interface providing Express-specific methods and configurations
  • File Upload System: Complete Multer integration with interceptors for various upload scenarios
  • Type System: Full TypeScript support with Express-specific interfaces and type definitions
  • Body Parser Integration: Configurable Express body parsing with raw body support

Capabilities

Express HTTP Adapter

Core Express.js integration providing HTTP server functionality, middleware support, static file serving, view rendering, and lifecycle hooks.

class ExpressAdapter extends AbstractHttpAdapter<http.Server | https.Server> {
  constructor(instance?: any);
  listen(port: string | number, callback?: () => void): Server;
  close(): Promise<void>;
  useStaticAssets(path: string, options: ServeStaticOptions): void;
  setViewEngine(engine: string): void;
  enableCors(options: CorsOptions | CorsOptionsDelegate<any>): void;
  useBodyParser<Options>(
    type: NestExpressBodyParserType, 
    rawBody: boolean, 
    options?: Options
  ): this;
}

function getBodyParserOptions<Options>(
  rawBody: boolean, 
  options?: Options
): Options;

Express HTTP Adapter

Application Interface

TypeScript interfaces and types for Express-based NestJS applications, including application configuration, body parser options, and static file serving.

interface NestExpressApplication<TServer = http.Server> extends INestApplication<TServer> {
  getHttpAdapter(): HttpServer<Express.Request, Express.Response, Express>;
  useStaticAssets(path: string, options?: ServeStaticOptions): this;
  setBaseViewsDir(path: string | string[]): this;
  setViewEngine(engine: string): this;
  useBodyParser<Options = NestExpressBodyParserOptions>(
    parser: NestExpressBodyParserType, 
    options?: Omit<Options, 'verify'>
  ): this;
  enableCors(options?: CorsOptions | CorsOptionsDelegate<any>): void;
}

type NestExpressBodyParserType = 'json' | 'urlencoded' | 'text' | 'raw';

Application Interface

File Upload System

Comprehensive file upload functionality using Multer with interceptors for single files, multiple files, file fields, and validation. Includes module configuration and error handling.

function FileInterceptor(
  fieldName: string, 
  localOptions?: MulterOptions
): Type<NestInterceptor>;

function FilesInterceptor(
  fieldName: string, 
  maxCount?: number, 
  localOptions?: MulterOptions
): Type<NestInterceptor>;

function FileFieldsInterceptor(
  uploadFields: MulterField[], 
  localOptions?: MulterOptions
): Type<NestInterceptor>;

class MulterModule {
  static register(options?: MulterModuleOptions): DynamicModule;
  static registerAsync(options: MulterModuleAsyncOptions): DynamicModule;
}

File Upload System

Common Types

interface ServeStaticOptions {
  dotfiles?: string;
  etag?: boolean;
  extensions?: string[];
  fallthrough?: boolean;
  immutable?: boolean;
  index?: boolean | string | string[];
  lastModified?: boolean;
  maxAge?: number | string;
  redirect?: boolean;
  setHeaders?: (res: any, path: string, stat: any) => any;
  prefix?: string;
}

interface NestExpressBodyParserOptions {
  inflate?: boolean;
  limit?: number | string;
  type?: string | string[] | ((req: any) => any);
  [key: string]: any;
}

interface MulterOptions {
  dest?: string;
  storage?: any;
  limits?: {
    fieldNameSize?: number;
    fieldSize?: number;
    fields?: number;
    fileSize?: number;
    files?: number;
    parts?: number;
    headerPairs?: number;
  };
  preservePath?: boolean;
  fileFilter?: (
    req: any, 
    file: any, 
    callback: (error: Error | null, acceptFile: boolean) => void
  ) => void;
}

interface MulterField {
  name: string;
  maxCount?: number;
}