Skip to content

INestApplication

reference
1 min readUpdated

Kind: Interface

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

Part of: Common

Interface defining the core NestApplication object.

INestApplication defines the public API for a running Nest HTTP application. It extends the application context capabilities with HTTP server configuration, middleware registration, microservice integration, lifecycle management, and network listening methods.

Diagram

mermaid
graph LR
  A[NestFactory.create] --> B[INestApplication]
  B --> C[Configure application]
  C --> C1[Middleware]
  C --> C2[CORS and versioning]
  C --> C3[Global prefix]
  C --> C4[WebSocket adapter]
  B --> D[Connect microservices]
  B --> E[Initialize and listen]
  E --> F[HTTP Server]
  F --> G[Clients]

Usage

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

async function bootstrap(): Promise<void> {
  const app: INestApplication = await NestFactory.create(AppModule);

  app.setGlobalPrefix('api');
  app.enableCors({
    origin: ['https://example.com'],
    credentials: true,
  });

  await app.listen(3000);

  console.log(`Application running at ${await app.getUrl()}`);
}

bootstrap();

AI Coding Instructions

  • Obtain an INestApplication through NestFactory.create() and configure it before calling listen().
  • Use setGlobalPrefix(), enableCors(), versioning, and middleware registration for application-wide HTTP behavior.
  • Use connectMicroservice() and startAllMicroservices() when building hybrid HTTP and microservice applications.
  • Prefer getHttpServer() only when an integration requires direct access to the underlying platform server.
  • Enable shutdown hooks when the application must gracefully handle process termination signals.

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)

  • getHttpBaseOptionsintegration/send-files/e2e/utils.ts:5
  • NestApplicationpackages/core/nest-application.ts:54
  • IEntryNestModulepackages/core/nest-factory.ts:39
  • NestExpressApplicationpackages/platform-express/interfaces/nest-express-application.interface.ts:20
  • NestFastifyApplicationpackages/platform-fastify/interfaces/nest-fastify-application.interface.ts:27
  • TestingModulepackages/testing/testing-module.ts:26

Was this page helpful?

Download as PDF
INestApplication — NestJS head-to-head