Nest.js

[Nest.js] 1 - Basic Structure

ESTJames 2021. 9. 7. 18:14

Content
1. Structure


1. Structure

initial files

  • src : consist of business logics
    • main.ts : create application and run
      import { NestFactory } from '@nestjs/core';
      import { AppModule } from './app.module';
      
      async function bootstrap() {
        const app = await NestFactory.create(AppModule); // AppModule is Root 
        await app.listen(3000);
      }
      
      bootstrap();​
    • app.module.ts : define app module, it roles as a root module which combines other modules.
      import { Module } from '@nestjs/common';
      import { AppController } from './app.controller';
      import { AppService } from './app.service';
      
      @Module({
        imports: [],
        controllers: [AppController],
        providers: [AppService],
      })
      export class AppModule {}​
    • XXX.spec.ts : codes for unit-test
  • test : consist of end to end test files
    • XXX.e2e-spec.ts : codes for e2e test
  • eslintrc.js : a library which helps developers have regulations to write codes
                       , a guideline of typescript, and a inspector for syntax errors
  • prettierrc : formatter for ' or " and indentation.
  • nest-cli.json : settings of a project, such as sourceRoot
  • tsconfig.json : settings how typescripts complie
  • ts.config.build.json : extension of tsconfig.json, settings for build, such as excludes not essential files
  • package.json : shows cli keywords, package's version