본문 바로가기
728x90

javascript40

NestJS | Repository pattern 여태까지 작성했던 패턴은 Client(browser) → ... → Controller → Service → DATA Source 순서로 진행됐었고, 실제 비즈니스 로직은 서비스 레이어에서 진행된다. Repository 패턴은 서비스 레이어와 데이터베이스 사이에 레포지토리 레이어 계층이 존재하여 레포지토리가 서비스와 DB를 중계하는 패턴을 말한다. 이 패턴은 여러 개의 서비스 레이어가 존재할 때 이점을 가질 수 있다. 예를 들어 A라는 서비스가 있고, 이는 A라는 데이터를 가져온다고 해보자. 이때 B라는 서비스에서 A데이터가 필요해서 A서비스에 접근한다. 그런데 A 역시 마찬가지로 B서비스의 모듈을 참조하는 코드가 있다면 순환 참조가 발생한다(순환 참조에 대해 정리했던 글). 이 문제는 어렵지 않게 해결.. 2023. 3. 5.
NestJS | NestJS와 DB 연결, 환경 변수 설정, DTO, 회원가입 기능 구현 MongoDB 연동 및 셋업 https://docs.nestjs.com/techniques/mongodb Documentation | NestJS - A progressive Node.js framework Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Progamming), FP (Functional Programming), and FRP (Functional Reac docs.nestjs.com NestJS에서 .. 2023. 2. 27.
NestJS | docs | Interceptors & AOP Pattern Interceptors 인터셉터는 @Injectable() 데코레이터를 주석으로 다는 클래스이고, NestInterceptor 인터페이스를 implements한다. 인터셉터는 Aspect Oriented Programming(AOP, 관점 지향 프로그래밍) 기술에서 영감 받은 유용한 기능들을 가지고 있다. bind extra logic before / after method execution transform the result returned from a function transform the exception thrown from a function extend the basic function behavior completely override a function depending on speci.. 2023. 2. 24.
NestJS | docs | Guards Guards 가드는 @Injectable() 데코레이터를 주석으로 다는 클래스이고, CanActivate 인터페이스를 implements 한다. 가드는 단일 책임(single responsibility)를 가진다. 이는 특정 상황에 따라 주어진 요청이 라우트 핸들러에 의해 다뤄지는지 결정한다. 가드는 인가(authorization)에 주로 사용된다. Express에서 인증 및 인가는 미들웨어에서 처리한다. 하지만 미들웨어로 인증 처리를 하면 next() 호출 이후에 어떤 핸들러가 실행되는지 모른다는 단점이 있다. 반면에 가드는 ExecutionContext 인스턴스에 접근하여 명확하게 다음에 실행되는 것이 무엇인지 알 수 있다고 한다. 즉 가드도 예외 필터나 파이프, 인터셉터처럼 요청/응답 사이클에서 더.. 2023. 2. 24.
NestJS | docs | Pipes Pipes 파이프는 PipeTransform 인터페이스를 구현하는 @Injectable() 데코레이터가 달린 클래스를 말한다. 즉 클라이언트 요청에서 들어오는 데이터를 유효성 검사 및 변환을 수행하여 서버가 원하는 데이터를 얻을 수 있도록 도와주는 클래스이다. 파이프는 두 유형으로 사용된다. transformation: 입력 데이터를 원하는 형식으로 변환 validation: 입력값의 유효성 검사. 실패한다면 예외 처리 Built-in pipes Nest는 즉시 사용할 수 있는 9개의 파이프를 제공한다. 이는 @nestjs/common 패키지에서 받아올 수 있다. ValidationPipe ParseIntPipe ParseFloatPipe ParseBoolPipe ParseArrayPipe ParseUU.. 2023. 2. 23.
NestJS | docs | Middleware Middleware 미들웨어는 라우트 핸들러 이전에 요청되는 함수이다. Nest의 미들웨어는 express의 미들웨어와 같다고 한다. 다음은 express 공식 문서에서 설명하는 미들웨어 함수의 기능들이다. 모든 코드를 실행한다. 요청 및 응답 객체를 변경한다. 요청-응답 주기를 종료한다. 스택에서 다음 미들웨어 함수를 호출한다. 현재 메들웨어 기능이 요청-응답 주기를 종료하지 않으면 next()를 호출해서 다음 미들웨어 함수로 넘겨야 한다. 그렇지 않으면 요청이 중단된다. 그리고 express같은 경우 미들웨어를 등록할 때 순서가 존재했었다. Nest도 마찬가지라고 한다. 또한 아래의 코드를 보면 @Injectable() 데코레이터를 볼 수 있다. 이는 Nest 미들웨어 역시 의존성 주입을 지원한다는 .. 2023. 2. 16.
NestJS | docs | Modules https://docs.nestjs.com/modules Documentation | NestJS - A progressive Node.js framework Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Progamming), FP (Functional Programming), and FRP (Functional Reac docs.nestjs.com Module 모듈은 @Module() 데코레이터로 주석이 달린 클.. 2023. 2. 16.
NestJS | docs | Provider https://docs.nestjs.com/providers Documentation | NestJS - A progressive Node.js framework Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Progamming), FP (Functional Programming), and FRP (Functional Reac docs.nestjs.com Providers Providers는 Nest에서 기본적인 개.. 2023. 2. 13.
NestJS | docs | First steps, controllers https://docs.nestjs.com/ Documentation | NestJS - A progressive Node.js framework Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Progamming), FP (Functional Programming), and FRP (Functional Reac docs.nestjs.com NestJS는 Node.js의 아키텍처 측면에서 효과적인 설계를 할 수 있도록.. 2023. 2. 11.
728x90
LIST