Today I Learned/TIL 08
-
2023 - 08 - 07 Nest.js TypeORM - Pipe 파이프Today I Learned/TIL 08 2023. 8. 7. 20:53
파이프 (Pipes) 파이프는 @Injectable () 데코레이터로 주석이 달린 클래스이다. 파이프는 data-transformation과 data validation을 위해 사용되며, 컨트롤러 경로 처리기에 의해 처리되는 인수에 대해 작동한다. 다음과 같이 URL 요청이 왔을 때, 먼저 해당 URL에 대한 데이터들을 처리해주는 것이다. 만약 문제가 생기면 통과하지 못하고 Error 처리되며, 통과한다면 데이터를 처리해준 채로 handler에게 가게 된다. Data Transformation 입력 데이터를 원하는 형식으로 변환하는 것을 말한다. 가령 문자열에서 정수로 바꾸는 것을 의미한다. Data Validation 유효성 체크로서, 입력 데이터를 평가하고 유효한 경우 변경되지 않은 상태로 전달된다...
-
2023 - 08 - 06 Nest.js 프로젝트 @module, 데코레이터, 루트모듈, imports, controllers, providers, exports, 의존성 주입 DI, IoC, DI, 제어 역전, 의존성(DI)Today I Learned/TIL 08 2023. 8. 6. 01:11
https://github.com/sangwoorhie/Nest.js.git GitHub - sangwoorhie/Nest.js Contribute to sangwoorhie/Nest.js development by creating an account on GitHub. github.com Nest.js 설치 명령어 npm i -g @nestjs/cli Nest.js 실행 명령어 (메뉴얼을 제공함) nest Nest.js 프로젝트 생성 명령어 $ nest new sparta-nest npm 선택 ? Which package manager would you ❤️ to use? (Use arrow keys) ❯ npm yarn pnpm Nest.js 프로젝트에서 만약 실패했다면, 아래 명령어 순서대로 입력하..
-
2023- 08 - 05 Nest.js : Express의 단점을 보완, feat. 레이어드 아키텍쳐Today I Learned/TIL 08 2023. 8. 5. 01:11
Node.js에는 여러가지 웹 프레임워크 (Express, Koa, Fasify, Nest.js .. )등이 있다. 이중에 Nest.js가 요새 가장 핫한 넷 프레임워크이다. Express가 물론 가장 대중적인 웹 프레임워크다. Express로 테스트 app.js코드를 만들어보자 const express = require('express') const app = express() app.get('/', function (req, res) { res.send('Hello World') }) app.listen(3000) // 3000번 포트로 WAS 서버 바로 띄우기! 여기서 조금 더 추가해보자. 클라이언트가 JSON데이터를 보낼때 해당 페이로드를 파싱하기 위해 body-parser미들웨어를 적용해야 함...
-
2023 - 08 - 04 타입스크립트 프로젝트 - 도서관 프로그램Today I Learned/TIL 08 2023. 8. 4. 01:10
오늘할일 : 타입스크립트 클래스, 상속, 인터페이스를 활용해서 도서관 프로그램 만들기. - 도서 추가 기능 - 사서 - 도서 삭제 기능 - 사서 - 도서 대여 기능 - 유저 - 도서 반납 기능 - 유저 1. 프로그램 셋팅 npm init -y tsc --init --rootDir ./src --outDir ./dist --esModuleInterop --module commonjs --strict true --allowJS true --checkJS true --rootDir ./src - 프로그램의 소스 파일이 들어가는 경로는 src 디렉토리 --outDir ./dist - 컴파일이 된 파일들이 들어가는 디렉토리는 dist 디렉토리 --esModuleInterop - CommonJS 방식의 모듈을 ES..
-
2023 - 08 - 03 객체지향 설계원칙 SOLIDToday I Learned/TIL 08 2023. 8. 1. 19:56
S.O.L.I.D. 1. S (SRP. 단일 책임원칙) → 클래스는 하나의 책임만 가져야 한다. 잘못된 사례: 사용자 조회 , 저장로직이 있는데, 갑자기 이메일 전송로직이 있다. 두개는 다른 책임이라서 같은 클래스 내에 있으면 안된다. class UserService { constructor(private db: Database) {} getUser(id: number): User { // 사용자 조회 로직 return this.db.findUser(id); } saveUser(user: User): void { // 사용자 저장 로직 this.db.saveUser(user); } sendWelcomeEmail(user: User): void { // 갑분 이메일 전송 로직이 여기 왜? const ema..
-
2023 - 08 - 02 타입스크립트 클래스 class, 서브타입, 슈퍼타입, upcasting, downcasting, 추상클래스, abstract, 인터페이스, interfaceToday I Learned/TIL 08 2023. 8. 1. 19:56
오늘 배운 것: 클래스 class, 서브타입, 슈퍼타입, upcasting, downcasting, 추상클래스, 인터페이스 class Animal { name: string; constructor(name: string) { this.name = name; } makeSound() { console.log('동물 소리~'); } } class Dog extends Animal { age: number; constructor(name: string) { super(name); this.age = 5; } makeSound() { console.log('멍멍!'); // 부모의 makeSound 동작과 달라요! } eat() { // Dog 클래스만의 새로운 함수 정의 console.log('강아지가 사료를..
-
2023 - 08 - 01 타입스크립트 : 객체지향 프로그래밍, 클래스, 생성자, 상속, 클래스 접근 제한자 public, private, protected, 부모클래스, 자식클래스, extends, 오버라이딩Today I Learned/TIL 08 2023. 8. 1. 19:55
클래스는 객체를 만들기 위한 틀 (template) 타입스크립트에서 클래스를 정의하기 위해 class 키워드를 사용하고, 클래스의 속성과 매서드를 정의한 뒤, new 키워드를 사용해서 객체를 생성할 수 있다. 객체는 클래스를 기반으로 생성되며, 클래스의 인스턴스(instance)라고도 한다. class Person { name: string; age: number; constructor(name: string, age: number) { // 생성자 this.name = name; this.age = age; } sayHello() { console.log(`안녕하세요! 제 이름은 ${this.name}이고, 나이는 ${this.age}살입니다.`); } } const person = new Person..