Eggy Dev DocsEggy Dev Docs

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

PathWhat it containsNote
src/Your application source codeMost of your work happens here
src/app.module.tsRoot module that wires pieces togetherWe will edit this when connecting MongoDB
src/app.controller.tsExample controller that returns “Hello World”Safe to delete later
src/app.service.tsExample service used by the controllerShows how dependency injection works
test/Sample end-to-end testLeave it as-is for now
package.jsonProject metadata and npm scriptsnpm run start:dev lives here
.eslintrc.jsLinting configurationHelps keep code style consistent

Module pattern refresher

Nest groups functionality into modules:

  1. Module (*.module.ts) gathers related providers and controllers.
  2. Controller handles HTTP requests (@Controller).
  3. 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.ts

Then 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.