NestJS
Initialization
Setting up a new NestJS application.
Install CLI & Create Project: Install the NestJS CLI globally and scaffold a new application.
terminal
bash
# Install the Nest CLI globally
npm i -g @nestjs/cli
# Create a new Nest application
nest new my-nest-project
# Start the application in watch mode
cd my-nest-project
npm run start:dev
Bootstrap Application: The entry file of the application which uses the core function `NestFactory.create()`.
src/main.ts
typescript
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
// Enable CORS if needed
app.enableCors();
// Set global prefix
app.setGlobalPrefix('api');
await app.listen(3000);
console.log(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();