Skip to content

NestApplicationOptions

reference
1 min readUpdated

Kind: Interface

Source: packages/common/interfaces/nest-application-options.interface.ts

Part of: Common

NestApplicationOptions configures runtime behavior when creating a Nest application instance. It controls HTTP concerns such as CORS, request body parsing, HTTPS server options, raw body access, and connection shutdown behavior.

Properties

PropertyType
cors`boolean
bodyParserboolean
httpsOptionsHttpsOptions
rawBodyboolean
forceCloseConnectionsboolean

Diagram

mermaid
graph LR
  A[NestFactory.create] --> B[NestApplicationOptions]
  B --> C[CORS Configuration]
  B --> D[Body Parser]
  B --> E[HTTPS Options]
  B --> F[Raw Body Access]
  B --> G[Connection Shutdown]
  C --> H[Nest Application]
  D --> H
  E --> H
  F --> H
  G --> H

Usage

ts
import { NestFactory } from '@nestjs/core';
import type { NestApplicationOptions } from '@nestjs/common';
import { AppModule } from './app.module';

async function bootstrap() {
  const options: NestApplicationOptions = {
    cors: {
      origin: ['https://example.com'],
      credentials: true,
    },
    bodyParser: true,
    rawBody: true,
    forceCloseConnections: true,
    httpsOptions: {
      key: process.env.HTTPS_KEY,
      cert: process.env.HTTPS_CERT,
    },
  };

  const app = await NestFactory.create(AppModule, options);

  await app.listen(3000);
}

bootstrap();

AI Coding Instructions

  • Pass NestApplicationOptions as the second argument to NestFactory.create() when configuring an HTTP-based Nest application.
  • Use cors: true for default CORS behavior, or provide CorsOptions/a delegate when origins and credentials require explicit control.
  • Enable rawBody only when integrations need the unparsed payload, such as webhook signature verification.
  • Keep bodyParser enabled unless registering custom parsing middleware or handling request streams manually.
  • Supply valid Node.js HTTPS server options through httpsOptions, and consider forceCloseConnections for reliable shutdown in long-lived connection environments.

Used by

6 references from 6 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (6)

  • AbstractHttpAdapterpackages/core/adapters/http-adapter.ts:8
  • NestApplicationpackages/core/nest-application.ts:54
  • IEntryNestModulepackages/core/nest-factory.ts:39
  • ExpressAdapterpackages/platform-express/adapters/express-adapter.ts:51
  • TestingModulepackages/testing/testing-module.ts:26
  • SocketModulepackages/websockets/socket-module.ts:27

Was this page helpful?

Download as PDF
NestApplicationOptions — NestJS head-to-head