Project Tour
Explore the files generated by Nest CLI.
Overview
Before writing code it's useful to know where everything lives. Nest follows a modular structure that keeps controllers, services, and modules in predictable places.
Key directories
| Path | What it contains | Note |
|---|---|---|
src/ | Your application source code | Most of your work happens here |
src/app.module.ts | Root module that wires pieces together | We will edit this when connecting MongoDB |
src/app.controller.ts | Example controller that returns “Hello World” | Safe to delete later |
src/app.service.ts | Example service used by the controller | Shows how dependency injection works |
test/ | Sample end-to-end test | Leave it as-is for now |
package.json | Project metadata and npm scripts | npm run start:dev lives here |
.eslintrc.js | Linting configuration | Helps keep code style consistent |
Module pattern refresher
Nest groups functionality into modules:
- Module (
*.module.ts) gathers related providers and controllers. - Controller handles HTTP requests (
@Controller). - Service contains reusable logic (
@Injectable).
We will create our own TasksModule later using this pattern.
Remove sample controller
To keep things clear you can remove the default “Hello World” files.
rm src/app.controller.ts src/app.controller.spec.ts src/app.service.tsThen open src/app.module.ts and remove references to AppController and AppService.
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
controllers: [],
providers: [],
})
export class AppModule {}Next, continue to Connect MongoDB to install database packages and set up configuration.