목록nest.js (5)
코딩일상
MonogoDB 연결하기 Nest는 MongoDB 데이터베이스와 통합하기 위한 두 가지 방법을 지원합니다. MongoDB용 커넥터가 있는 내장 TypeORM 모듈을 사용하거나 가장 널리 사용되는 MongoDB 객체 모델링 도구인 Mongoose 를 사용할 수 있습니다. 이번 포스팅에서는 Mongoose를 이용하여 진행 $ npm i @nestjs/mongoose mongoose Mongoose 공식문서 Mongoose v6.7.5: Schemas If you haven't yet done so, please take a minute to read the quickstart to get an idea of how Mongoose works. If you are migrating from 5.x to 6.x..
Exception 적용전 기본 nest 자체 에러처리 값 HttpException을 적용한경우 HttpException('메세지', HTTPstatusCode)를 넣어서 사용을 할수가 있다. //cats.controller.ts @Controller('cats') export class CatsController { //dependency injection 의존성 주입 constructor(private readonly catsService: CatsService) {} // cats/ @Get() getAllcat() { throw new HttpException('message', 401); return 'get all cat api'; } HttpException을 커스터마이징 한경우 //cats...
미들웨어 미들웨어는 라우트 핸들러 보다 먼저 호출되는 함수입니다 . 미들웨어 기능은 애플리케이션의 요청-응답 주기에서 요청 및 응답 객체 와 미들웨어 기능에 액세스할 수 있습니다 . next()다음 미들웨어 기능은 일반적으로 라는 변수로 표시 됩니다next . Nest 미들웨어는 기본적으로 express 미들웨어와 동일합니다. 공식 익스프레스 문서의 다음 설명은 미들웨어의 기능을 설명합니다. 로깅파일만들기 CLI 명령어 이용 $ nest g middleware logger 1)Documentation그대로 logging을 할 경우 import { Injectable, NestMiddleware } from '@nestjs/common'; import { NextFunction, Request, Respo..
nest.js에서 모듈 파일을 생성하는 방법 CLI를 이용하여 손쉽고 안전하게 파일과 폴더를 만들어낼 수 있다. *아래 내용들은 nest.js document를 참고하여 작성하였습니다. 1. 모듈 파일 생성 방법 nest generate Generates and/or modifies files based on a schematic $ nest new [options] $ nest n [options] $ nest g mo cats 사용하는 이유 그냥 폴더를 만들어도 되지만 CLI명령어를 사용하면 app.module.ts에서 7번째 줄에 보면 module에 자동으로 들어가게 된다. 에러 방지를 하는데 기여할 수 있음 2. 컨트롤러 파일 생성 방법 $ nest g co cats 위 명령어를 사용하면 cats..
nest.js 공식문서를 최대한 참고하여진행하였다. 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 1.nest.js를 설치할 폴더로 들어간다. $ npm i -g @ne..