Careeroza
Project Structure and main.ts
The Generated Folder Tree
shopease-api/ ├── src/ │ ├── app.controller.ts # sample controller (GET /) │ ├── app.controller.spec.ts # unit test for it │ ├── app.module.ts # root module │ ├── app.service.ts # sample service │ └── main.ts # entry point: creates and starts the app ├── test/ │ ├── app.e2e-spec.ts # end-to-end test │ └── jest-e2e.json ├── nest-cli.json # CLI settings ├── package.json ├── tsconfig.json # experimentalDecorators + emitDecoratorMetadata are ON └── tsconfig.build.json
main.ts: Starting the App
src/main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule); // builds the DI container from the root module
app.setGlobalPrefix('api'); // every route now starts with /api
app.enableCors(); // allow the Next.js storefront to call us
await app.listen(process.env.PORT ?? 3000);
}
bootstrap();src/app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [], // other modules this module needs
controllers: [AppController], // HTTP entry points
providers: [AppService], // services NestJS should create and inject
})
export class AppModule {}Note: NestJS relies on two compiler options in tsconfig.json: experimentalDecorators and emitDecoratorMetadata. The second one stores constructor parameter types, which is how NestJS knows what to inject.