NestFactory
Bootstraps a Nest application by creating an application instance from the root module.
Syntax
NestFactory.create(module, options?) | NestFactory.createMicroservice(module, options?) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
module | Type | No | The root application module class. |
options | NestApplicationOptions | No | Optional settings such as logger, cors, and bodyParser. |
Returns
Promise<INestApplication> — A promise resolving to the application instance.
Examples
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
await app.listen(3000);
}
bootstrap();
Notes
NestFactory.create() builds an HTTP application; createMicroservice()
builds a microservice transport. Global pipes, filters, interceptors, and
guards are registered on the returned app instance before listen().