GithubHelp home page GithubHelp logo

nest-pratice's Introduction

NestJS 기본 구조 설명

  • nest-cli.json : nest 프로젝트를 위해 특정한 설정을 할 수 있는 json 파일
  • tsconfig.build.json : tsconfig.json 의 확장 파일이며, build를 할 때 필요한 설정들 "excludes" 에서는 빌드할 때 필요 없는 파일들 명시
  • src/main.ts : 앱을 생성하고 실행
  • src/app.module.ts: 앱 모듈을 정의

NestJS Module

  • @Module() 데코레이터로 주석이 달린 클래스
  • => NestJS가 애플리케이션 구조를 구성하는데 사용하는 메타 데이터를 제공
  • 구조는 루트 모듈과 그 하부 기능모듈을 가진다.
  • 각 기능 별로 모듈을 뭉치기 땜ㄴ에, UserController, UserService, UserEntity 다 같은 기능이기에 UserModules 안에 넣는다.
  • 모듈은 기본적으로 싱글톤 이므로 여러 모듈 간에 쉽게 공급자의 동일한 인스턴스를 공유 할 수 있다. (Shared Module)
  • 생성 명령어 nest g module [boards]

[Controller]

  • @Controller() 데코레이터로 클래스를 데코레이션하여 정의됩니다.
  • Handler 메서드를 가진다. (@Get, @Post, @Delete, @Patch, @Put)
  • nest g controller [boards] --no-spec

Providers

  • 프로바이더는 Nest의 기본 개념입니다.
  • 대부분의 기본 Nest 클래스는 서비스, 리포지토리, 팩토리, 헬퍼등 프로바이더로 취급될 수 있습니다.
  • 프로바이더의 주요 아이디어는 종속성으로 주입할 수 있다는 것입니다.
  • 즉, 객체는 서로 다양한 관계를 만들 수 있으며 객체의 인스턴스를 "연결"하는 기능은 대부분 Nest 런타임 시스템에 위임될 수 있습니다.

Service

  • @Injectable() 데코레이터로 감싸져서 모듈에 제공된다. ,, 애플리케이션 전체에서 사용된다.
  • 데이터 유효성 체크, 데이터베이스의 아이템을 생성하는 등의 작업을 처리
  • controller 에서 주로 사용되고, 처음에 constructor로 생성해줘야 한다.
  • nest g service boards --no-spec

Pipe : @Injectable() 데코레이터로 주석이 달린 클래스

data transformation 과 data validation 을 위해서 사용 됩니다.
  • Binding Pipes

    • Handler-level Pipes > @UsePipes()
    • Parameter-level Pipes > @Body(name, ParameterPipe)
    • Global-level Pipes > app.useGlobalPipes(GlobalPipes)
  • Built-in Pipes

    • ValidationPipe
    • ParseIntPipe
    • ParseBoolPipe
    • ParseArrayPipe
    • ParseUUIDPipe
    • DefaultValuePipe
  • Repository : 레포지토리는 엔터티 객체와 함께 작동하며 엔티티 찾기, 삽입, 업데이트, 삭제 등을 처리

  • 데이터베이스에 관련된 일을 서비스가 아닌 레포지토리에서 한다

    • 레포지토리 패턴
  • MiddleWare

    • Pipes: 파이프는 요청 유효성 검사 및 payload 변환을 위해 만들어집니다. 데이터를 예상한대로 직렬화합니다.

    • Filters: 필터는 오류 처리 미들웨어 입니다. 특정 오류 처리기를 사용할 경로와 각 경로 주변의 복잡성을 관리하는 방법을 알 수 있습니다.

    • Guards: 가드는 인증 미들웨어입니다. 지정된 경로로 통과할 수 있는 사람과 허용되지 않는 사람을 서버에 알려줍니다.

    • Interceptors: 인터셉터는 응답 매핑 및 캐시 관리와 함께 요청 로깅과 같은 전후 미들웨어 입니다. 각 요청 전후에 이를 실행하는 기능은 매우 강력하고 유용합니다.

    • called order middleware -> guard -> interceptor(before) -> pipe -> controller -> service -> controller -> interceptor(after) -> filter(if applicable) -> client

  • 로그에 대해서

    • Log : 중요한 정보의 범용 로깅
    • Warning : 치명적이거나 파괴적이지 않은 처리되지 않은 문제
    • Error : 치명적이거나 파괴적인 처리되지 않은 문제
    • Debug : 오류 발생 시 로직을 디버그하는데 도움이 되는 유용한 정보 입니다. 개발자용
    • Verbose : 응용 프로그램의 동작에 대한 통찰력을 제공하는 정보입니다.

ref. https://github.com/jaewonhimnae/nestjs-board-app.git

nest-pratice's People

Contributors

bradiian avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.