What is the main.ts file in a NestJS application?
Answer
The main.ts file is the entry point of a NestJS application. It uses the NestFactory to bootstrap the application: const app = await NestFactory.create(AppModule);. This function creates the NestJS IoC container and compiles the module dependency graph. After creating the app instance, you configure global settings: app.useGlobalPipes(new ValidationPipe()), app.enableCors(), app.setGlobalPrefix('api'), Swagger setup. Then start listening: await app.listen(3000);. In production, you might read the port from process.env.PORT. The AppModule is the root module that imports all feature modules, making it the composition root of the application.
Previous
What are Exception Filters in NestJS?
Next
What is the difference between @Res() and res in NestJS?