Express.js HTTP platform adapter for NestJS applications with comprehensive file upload capabilities
npx @tessl/cli install tessl/npm-nestjs--platform-express@11.1.0NestJS 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.
npm install @nestjs/platform-expressimport {
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');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();NestJS Platform Express is built around several key components:
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;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';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;
}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;
}