Express์์ Nest๋ก ์ฒ์ ๋์ด๊ฐ์ ๋, Nest์ ์ํคํ ์ฒ๋ฅผ ์ดํดํ๋ ๊ฒ์ด ๊ฝค๋ ์ด๋ ค์ ๋ค.
๊ณต์๋ฌธ์๋ฅผ ์ฝ๊ณ ์ด๋ ์ ๋๋ ์ดํดํ๋ค๊ณ ์๊ฐํ ์ํ๋ก ์ผ๋จ ๋ญ๋ผ๋ ์ง์ ๋ง๋ค์ด๋ณด์ ๋ผ๋ ์๊ฐ์ ๊นํ๋ธ์ ๋ค๋ฅธ ๊ฐ๋ฐ์๋ค์ด Nest๋ฅผ ์ฌ์ฉํ ์ฝ๋๋ฅผ ์ฌ๋ ค๋ ๋ฆฌํฌ์งํ ๋ฆฌ๋ฅผ ์ฐธ๊ณ ํด์ ๋ฌด์์ ๋ฐ๋ผ ๋ง๋ค๊ณ ์ฌ๋ฌ ์ฝ๋๋ฅผ ๋๋ฌ๋ดค์๋๋ฐ
๊ฐ๋ฐ์๋ค๋ง๋ค ๋๊ตฌ๋ types, ๋๊ตฌ๋ interface, class๋ฅผ ์ฌ๊ธฐ์ ๊ธฐ์ ์ฌ์ฉํ๊ณ ์๋ ๊ฑธ ๋ณด๋ ์ ๋ค ๋ค๋ฅด๊ฒ ์ฌ์ฉํ๊ณ ์๋ ๊ฑด์ง ํผ๋์ค๋ฝ๊ธฐ๋ง ํ๊ณ , ์ด๊ฒ๋ค์ ๋๋์ฒด ์ธ์ ์ด๋์ ์ฐ๋ ๊ฑด์ง ๊ถ๊ธํด์ก๋ค.
ํ์ ์ ์ ์ํ๋ ์ด์ ?
์ฐ์ ์ธ๊ฐ์ง ๋ฐฉ์์ ๋ค๋ฃจ๊ธฐ์ ์์ ์ด ์ธ ๊ฐ์ง ๋ฐฉ์ ๋ชจ๋ ํ์ ์ ์ ์ํ๋๋ฐ ์ฌ์ฉํ๋ ๋ฌธ๋ฒ์ด๋ผ๋ ๊ฒ์ ์ง๊ณ ๋์ด๊ฐ๋ค.
ํ์ ์ ์ ์ํ๋ ๊ฒ์ ์ ํ์ฌํญ์ด์ง๋ง, ํ์ ์ ์ ์ํ๋ ๊ฒ์ผ๋ก์ ์ปดํ์ผ ํ์์ ํ์ ์ค๋ฅ๋ฅผ ๋ฐฉ์งํ ์ ์๊ณ , ์ฝ๋์ ๊ฐ๋ ์ฑ์ ํฅ์ํด ์ฝ๋ ์ ์ฅ์์ ๋ ์ฝ๋๋ฅผ ์ฝ๊ฒ ์ดํดํ๋ฉฐ ์ฝ์ ์ ์๋ค. (readable)
์ธ ๊ฐ์ง ๋ฐฉ์์ ์ฐจ์ด
Interface
ํ์ ์ ์์ ๊ธฐ๋ณธ์ ์ธํฐํ์ด์ค๋ค. ๋ณ์์ ํ์ ๋ง์ ์ฒดํฌํ๋ ๋ฐฉ์์ผ๋ก ์ฃผ๋ก ๊ฐ์ฒด์ ํ์ ์ ์ ์ํ ๋ ์ฌ์ฉํ๋ค.
// user.interface.ts
export interface IUser {
id: number;
username: string;
email: string;
}
export class UserService {
private users: IUser[] = [];
createUser(user: IUser): IUser {
this.users.push(user);
return user;
}
getUsers(): IUser[] {
return this.users;
}
}
Type
type์ ์ ์ฐํ ํ์ ์ ์๊ฐ ๊ฐ๋ฅํ๋ค. ์ธํฐํ์ด์ค์ ๋น์ทํ์ง๋ง, ๊ฐ์ฒด ํ์ ์ธ์๋ ์ ๋์ธ ํ์ , ๊ต์ฐจ ํ์ ๋ฑ ๋ณต์กํ ๊ตฌ์กฐ๋ฅผ ์ ์ํ ์ ์๋ค.
// user.type.ts
export type User = {
id: number;
username: string;
email: string;
};
export type Admin = User & {
role: 'admin';
};
export class UserService {
private users: User[] = [];
createUser(user: User): User {
this.users.push(user);
return user;
}
getUsers(): User[] {
return this.users;
}
}
Class
class๋ ์ค์ ๊ตฌํ์ฒด์ ํด๋น๋๋ค. ๋ณ์์ ํ์ ๋ ์ฒดํฌํ๊ณ , ๊ฐ์ฒด์ ์ธ์คํด์ค ๋ํ ์์ฑํ ์ ์๋ ํ ํ๋ฆฟ์ ์ ๊ณตํ๋ค.
๋ฉ์๋์ ์์ฑ์๋ฅผ ํฌํจํ ์ ์๋ค.
// user.class.ts
export class User {
constructor(
public id: number,
public username: string,
public email: string,
) {}
displayInfo(): string {
return `${this.username} - ${this.email}`;
}
}
export class UserService {
private users: User[] = [];
createUser(user: User): User {
this.users.push(user);
return user;
}
getUsers(): User[] {
return this.users;
}
}
๊ทธ๋์ ์ธ์ ๋ฌด์์ ์จ์ผํ ๊น?
์ฌ๋ฌ ์ํฉ์ ๋ง์ถฐ์ 3๊ฐ์ง ๋ฐฉ์์ ๊ฐ๊ฐ ์ธ์ ํ์ฉํ๋ฉด ์ข์์ง ์์๋ณด์.
1. ๋ฐ์ฝ๋ ์ดํฐ์ ๋ฉํ๋ฐ์ดํฐ
@Entity('users')
@Unique(['login_id'])
export class UserEntity {
@PrimaryGeneratedColumn({ type: 'int', unsigned: true })
id: number;
@Column({ type: 'varchar', length: 30, nullable: false })
login_id: string;
// ...
}
NestJS๋ฅผ ์ฌ์ฉํ๋ค ๋ณด๋ฉด, ๋๋ถ๋ถ์ ์ํฉ์์ ๋ฐ์ฝ๋ ์ดํฐ๋ก ๋ชจ๋ ๊ฒ์ ์ ์ดํ๋ ๊ฒ์ ์ ์ ์๋ค.
๊ทธ๋ฐ๋ฐ interface์ ๊ฒฝ์ฐ ์ปดํ์ผ ํ์ ์ฌ๋ผ์ง๊ธฐ ๋๋ฌธ์ ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
์ด๋ฐ ๋งฅ๋ฝ์์ DTO๋ Pipe ๊ฐ์ ์์๋ ๋ฐํ์์์ ์ฌ์ฉํ ์ ์๋ ๊ฒ์ด ์ค์ํ๊ธฐ ๋๋ฌธ์
์ธํฐํ์ด์ค๋ณด๋ค ํด๋์ค๊ฐ ์ ํธ๋๋ค.
2. ์์กด์ฑ ์ฃผ์ (DI)
์ค์ ํ๋ก์ ํธ์์๋ Type -> Repository -> Service -> Module ์์๋ก ์ฌ์ฉ๋๋ฉฐ ์์กด์ฑ์ด ์ค์ ๋๋ค.
// product.types.ts
// 1. ํ์
์ ์: ์ํฐํฐ์ Repository ์ธํฐํ์ด์ค
interface Product {
id: number;
name: string;
price: number;
}
export const PRODUCT_REPOSITORY = Symbol('PRODUCT_REPOSITORY');
interface IProductRepository {
findOne(id: number): Promise<Product>;
save(product: Omit<Product, 'id'>): Promise<Product>;
}
// product.repository.ts
// 2. Repository ๊ตฌํ์ฒด
import { Injectable } from '@nestjs/common';
import { IProductRepository, Product, PRODUCT_REPOSITORY } from './product.types';
@Injectable()
export class ProductRepository implements IProductRepository {
async findOne(id: number): Promise<Product> {
// ์ค์ DB ์กฐํ ๋ก์ง
return { id, name: 'Laptop', price: 1000 };
}
async save(product: Omit<Product, 'id'>): Promise<Product> {
// ์ค์ DB ์ ์ฅ ๋ก์ง
return { id: 1, ...product };
}
}
// product.service.ts
// 3. Service์์ Repository ์ฌ์ฉ
// service์์ interface repo๋ฅผ ์ฐ๋ ์ด์ ๋ ์ค์ repo์ service์ ๊ฒฐํฉ์ฑ์ ๋ฎ์ถ๊ธฐ ์ํจ
import { Injectable } from '@nestjs/common';
import { IProductRepository, Product, PRODUCT_REPOSITORY } from './product.types';
import { Inject } from '@nestjs/common';
@Injectable()
export class ProductService {
constructor(
@Inject(PRODUCT_REPOSITORY)
private readonly productRepository: IProductRepository,
) {}
async getProductById(id: number): Promise<Product> {
return this.productRepository.findOne(id);
}
async createProduct(name: string, price: number): Promise<Product> {
return this.productRepository.save({ name, price });
}
}
// product.module.ts
// 4. Module์์ ์์กด์ฑ ์ค์
import { Module } from '@nestjs/common';
import { ProductService } from './product.service';
import { ProductRepository } from './product.repository';
import { PRODUCT_REPOSITORY } from './product.types';
@Module({
providers: [
ProductService,
{
provide: PRODUCT_REPOSITORY,
useClass: ProductRepository,
},
],
exports: [ProductService],
})
export class ProductModule {}
์ด ๊ตฌ์กฐ๋ NestJS์ ์์กด์ฑ ์ฃผ์ (DI) ์์คํ ์ ๊ธฐ๋ฐ์ผ๋ก ๋์ํ๋ค.
1. ์ปดํ์ผ ํ์: TypeScript๊ฐ ํ์ ์ ์ฒดํฌํ๋ ์์
- IProductRepository ์ธํฐํ์ด์ค์ ๋ฉ์๋๋ค์ด ์ ๋๋ก ๊ตฌํ๋์๋์ง ํ์ธ
- ๋ฉ์๋์ ํ๋ผ๋ฏธํฐ์ ๋ฐํ ํ์ ์ด ์ผ์นํ๋์ง ๊ฒ์ฌ
2. ๋ฐํ์: ์ค์ JavsScript๊ฐ ์คํ๋๋ ์์
- ์ธํฐํ์ด์ค๋ ์ฌ๋ผ์ง๊ณ ์์
- PRODUCT_REPOSITORY ํ ํฐ์ ์ฌ์ฉํด ProductRepository ํด๋์ค๋ฅผ ์ธ์คํด์คํํ์ฌ ์๋น์ค์ ์ฃผ์
3. Type์ ํ์ฉ
3-1. ์ ๋์จ ํ์ ์ผ๋ก ๊ฐ์ ์ ํํ ์ ์๋ค.
์ ๋์จ ํ์ ์ ์ฌ๋ฌ ๊ฐ์ง ๊ฐ๋ฅํ ๊ฐ ์ค ํ๋๋ฅผ ์ง์ ํ ๋ ์ฌ์ฉํ๋ค. ์ด๋ฅผ ํตํด ํน์ ๊ฐ์ด ํ์ฉ๋๋ ๋ฒ์๋ฅผ ์ ํํ ์ ์๋ค.
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
type UserRole = 'admin' | 'manager' | 'user' | 'guest';
type ValidationStatus = 'idle' | 'pending' | 'success' | 'error';
3-2. ์ํ ๊ด๋ฆฌ๋ฅผ ์ํ ์ฐจ๋ณํ๋ ํ์
์ํ๋ฅผ ๊ด๋ฆฌํ ๋ ๊ฐ ์ํ์ ๋ฐ๋ผ ๋ค๋ฅด๊ฒ ์ฒ๋ฆฌํ ์ ์๋๋ก ํ์ ์ ์ ์ํ๋ค. ์ฌ๊ธฐ์ ์ ๋ค๋ฆญ์ ํ์ฉํ๋ฉด ์ํ์ ๋ง๋ ๋ฐ์ดํฐ๋ฅผ ์ ๋์ ์ผ๋ก ๊ด๋ฆฌํ ์ ์๋ค.
type RequestState<T> =
| { status: 'idle' }
| { status: 'loading' }
| { status: 'success'; data: T }
| { status: 'error'; error: Error };
3-3. ์ ํธ๋ฆฌํฐ ํ์ ์ ํ์ฉํ ํ์ ๋ณํ
:Omit, Partial, Pick ๊ฐ์ ์ ํธ๋ฆฌํฐ ํ์ ์ ์ฌ์ฉํ์ฌ ๊ธฐ์กด์ ํ์ ์ ๋ณํํ๊ฑฐ๋, ์ผ๋ถ ํ๋๋ง ์ ํํ ์๋ ์๋ค.
interface User {
id: number;
name: string;
email: string;
password: string;
role: UserRole;
createdAt: Date;
}
type CreateUserDto = Omit<User, 'id' | 'createdAt'>; // id, createdAt ์ ์ธ
type UpdateUserDto = Partial<Pick<User, 'name' | 'email'>>; // name, email๋ง ์ ํ์
type SafeUser = Omit<User, 'password'>; // password ์ ์ธ
3-4. ์ด๋ฒคํธ ํ์ ์ ์
type UserCreatedEvent = { type: 'USER_CREATED'; userId: number; timestamp: Date; }
type UserDeletedEvent = { type: 'USER_DELETED'; userId: number; reason: string; timestamp: Date; }
type UserEvent = UserCreatedEvent | UserDeletedEvent;
์ด๋ฒคํธ ์์คํ ์ ๋ฐ์ํ ์ ์๋ ์ฌ๋ฌ ์ด๋ฒคํธ์ ํ์ ์ ์ ์ํ์ฌ, ํด๋น ์ด๋ฒคํธ์ ๋ง๋ ์ฒ๋ฆฌ๋ฅผ ํ ์ ์๋ค.
์ ์์์์ UserEvent๋ ์ฌ๋ฌ ์ด๋ฒคํธ๋ฅผ ์ ๋์จ ํ์ ์ผ๋ก ๋ฌถ์ด, ์ด๋ฒคํธ ์ข ๋ฅ์ ๋ฐ๋ผ ์ ์ ํ ์ฒ๋ฆฌ๊ฐ ๊ฐ๋ฅํ๋๋ก ํ ์ ์๋ค.
NestJS์์๋ type์ ์ด๋ฐ ์์ผ๋ก ํ์ฉํ๋ฉด ์ ์ฉํ๋ค.
@Injectable()
class UserEventEmitter {
@OnEvent('user.*')
handleUserEvent(payload: UserEvent) {
switch(payload.type) {
case 'USER_CREATED':
// payload๊ฐ UserCreatedEvent๋ก ํ์
์ถ๋ก ๋จ
break;
case 'USER_DELETED':
// payload๊ฐ UserDeletedEvent๋ก ํ์
์ถ๋ก ๋จ
break;
}
}
}
3-5. ๋ณต์กํ ์ํ ๊ด๋ฆฌ
์ํ๋ฅผ ๋ ๋ณต์กํ๊ฒ ๊ด๋ฆฌํ ๋๋ ์ฌ๋ฌ ํ๋๋ฅผ ๊ฐ๋ ํ์ ์ ์ ์ํ์ฌ ์ํ์ ๋ณํ๋ฅผ ์ถ์ ํ ์ ์๋ค.
type CacheState<T> = {
data: T | null;
lastUpdated: Date | null;
isLoading: boolean;
error: Error | null;
};
์ฌ๊ธฐ์ CacheState <T>๋ ์บ์ ์ํ๋ฅผ ๊ด๋ฆฌํ๋ฉฐ, ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๊ณ ์ ๋ฐ์ดํธ ์๊ฐ์ ์ถ์ ํ๊ณ , ๋ก๋ฉ ์ํ ๋ฐ ์ค๋ฅ๋ฅผ ๊ด๋ฆฌํ๋ค.
@Injectable()
class CacheService<T> {
private state: CacheState<T> = {
data: null,
lastUpdated: null,
isLoading: false,
error: null
};
}
์ค์ ์์ ์ ํ์ ๊ธฐ์ค
Interface์ ๊ฐ์ : ํ์ฅ๊ณผ ์์
Interface๋ ์ฃผ๋ก ์๋์ ๊ฐ์ ์ํฉ์์ ์ ํํ๊ธฐ ์ ํฉํ๋ค.
1. API ์๋ต์ฒ๋ผ ํ์ฅ ๊ฐ๋ฅ์ฑ์ด ๋์ ๊ฐ์ฒด ๊ตฌ์กฐ
interface ApiResponse {
status: number;
message: string;
}
interface DetailedApiResponse extends ApiResponse {
data: unknown;
timestamp: Date;
}
interface PaginatedApiResponse extends DetailedApiResponse {
page: number;
totalPages: number;
hasNext: boolean;
}
์ด ๊ฒฝ์ฐ ์ธํฐํ์ด์ค๋ ์์์ ํตํด ์ฌ๋ฌ ๊ฐ์ง ์๋ต ๊ตฌ์กฐ๋ฅผ ํ์ฅํ ์ ์์ด ์ ์ฉํ๋ค.
2. ํ๋ฌ๊ทธ์ธ์ด๋ ์ธ๋ถ์ ๊ณต๊ฐ๋๋ API
interface Plugin {
init(): void;
destroy(): void;
}
์ธ๋ถ ์์คํ ์์ ๊ตฌํํด์ผ ํ ๋ฉ์๋๋ค์ด๋ ๊ธฐ๋ฅ์ ์ ์ํ ๋ ์ ์ฉํ๋ค. ํ๋ฌ๊ทธ์ธ์ ์์ฑํ ๋, ์ธ๋ถ์์ ๊ตฌํํด์ผ ํ ๋ฉ์๋๋ฅผ ๋ช ํํ๊ฒ ๊ท์ ํ ์ ์๋ค.
3. DB ์ํฐํฐ์ฒ๋ผ ๋ช ํํ ์คํค๋ง๊ฐ ์๋ ๊ฐ์ฒด
interface User {
id: number;
name: string;
email: string;
createdAt: Date;
}
DB ์ํฐํฐ๋ ๋ชจ๋ธ์ฒ๋ผ ๊ณ ์ ๋ ๊ตฌ์กฐ๋ฅผ ๊ฐ๋ ๊ฐ์ฒด์์๋ interface๊ฐ ์ ์ฉํ๋ค. ๋ช ํํ ์คํค๋ง๋ฅผ ์ ์ํ์ฌ ๋ฐ์ดํฐ์ ํํ๋ฅผ ์ผ๊ด๋๊ฒ ๊ด๋ฆฌํ ์ ์๋ค. (๋ค๋ง ORM ๋ฑ์ ๋์ ํ์ฌ ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ์ํฐํฐ์ ์ ์ฉํด์ผ ํ๋ ๊ฒฝ์ฐ์๋ ํด๋์ค๊ฐ ์ ํฉ)
Type์ ๊ฐ์ : ์ ์ฐ์ฑ๊ณผ ์ ๊ตํ ํ์ ์ ์
1. ํํ ํ์ ์ ์
ํํ์ ์ ์ํ ๋ ์ฌ์ฉ๋๋ค. ๊ฐ ์์๊ฐ ํน์ ํ์ ์ ๊ฐ์ง ์ ์์ผ๋ฉฐ, ์ ํํ ์์น์ ํ์ ์ ์ง์ ํ ์ ์๋ค.
type Point = [number, number]; // 2D ์ขํ
type RGB = [number, number, number]; // RGB ์์
type StateChange = [string, any]; // [key, value] ํํ
2. ์ ๋์จ ํ์ ์ผ๋ก ์ ํํ ๊ฐ ์ ํ
์ ๋์จ ํ์ ์ ํน์ ๊ฐ ์ค ํ๋๋ง ํ์ฉํ๋ ํ์ ์ ์ ์ํ ๋ ์ฌ์ฉ๋๋ค. ์ฌ๋ฌ ๊ฐ์ง ๊ฐ๋ฅํ ๊ฐ ์ค์์ ์ ํ ๊ฐ๋ฅํ ๊ฐ์ ์ ํํ ์ ์๋ค.
type Status = 'idle' | 'loading' | 'success' | 'error'; // ์ํ ๊ฐ
type Theme = 'light' | 'dark' | 'system'; // ํ
๋ง ์ ํ
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE'; // HTTP ๋ฉ์๋
3. ์ ํธ๋ฆฌํฐ ํ์ ์ ํ์ฉํ ๋ณํ
์ ํธ๋ฆฌํฐ ํ์ ์ ๊ธฐ์กด ํ์ ์ ๋ณํํ๊ฑฐ๋ ํ์ํ ๋ถ๋ถ๋ง ์ ํํ ๋ ์ ์ฉํ๋ค. ํ์ ์ ๋ณํํ๊ฑฐ๋ ๋ถ๋ถ์ ์ผ๋ก ์ ํํ ์ ์๋ค.
interface User {
id: number;
name: string;
email: string;
password: string;
}
type CreateUser = Omit<User, 'id'>; // 'id' ์ ์ธํ CreateUser ํ์
type UpdateUser = Partial<Pick<User, 'name' | 'email'>>; // name๊ณผ email๋ง ์ ํ์
type SafeUser = Omit<User, 'password'>; // password ์ ์ธํ SafeUser ํ์
4. ํ ํ๋ฆฟ ๋ฆฌํฐ๋ด ํ์
ํ ํ๋ฆฟ ๋ฆฌํฐ๋ด ํ์ ์ผ๋ก ๋ฌธ์์ด ํ์ ์ ๋์ ์ผ๋ก ์์ฑํ ์ ์๋ค.
type CssUnit = `${number}px` | `${number}rem` | `${number}em`; // CSS ๋จ์
type EventName = `user:${string}`; // user:๋ก ์์ํ๋ ์ด๋ฒคํธ ์ด๋ฆ
๊ฒฐ๋ก
๊ฒฐ๊ตญ ์ธ ๊ฐ์ง ๋ฐฉ์ ์ค ๋ฌด์์ ์ ํํด์ผ ํ๋๋๋ ๊ฐ์์ ์๋ฆฌ๊ฐ ์๊ธฐ ๋๋ฌธ์ ๊ทธ๋๊ทธ๋ ์์์ ์ ๊ฐ๋ค ์จ์ผ ํ๋ค๋ ๊ฒฐ๋ก ์ด๋ค.
๊ฐ๋ตํ๊ฒ ์ ๋ฆฌํ ์ ํ ๊ธฐ์ค์ ๋ค์๊ณผ ๊ฐ๋ค.
1. Interface - ์ปดํ์ผ ํ์์ ํ์ ์์ ์ฑ ์ ๊ณต
- ๊ฐ์ฒด ๊ตฌ์กฐ๋ฅผ ์ ์ํ ๋
- ํ์ฅ ๊ฐ๋ฅ์ฑ์ด ์๋ API ์ค๊ณ
- ๋ช ํํ ๊ณ์ฝ(contract)์ด ํ์ํ ๋
- Repository๋ Service์ ๋ช ์ธ ์ ์
2. Type - ํ์ ๋ณํ, ์กฐํฉ ์ฒ๋ฆฌ์ ์ ์ฉ
- ์ ํํ ๊ฐ์ ์งํฉ์ ์ ์ํ ๋
- ํ์ ๋ณํ์ด๋ ์กฐํฉ์ด ํ์ํ ๋
- ํํ์ด๋ ์ ๋์จ ํ์ ์ ์ ์ํ ๋
- ๊ธฐ์กด ํ์ ์ ๋ณํํด์ ์๋ก์ด ํ์ ์ ๋ง๋ค ๋
3. Class ์ฌ์ฉ์ฒ - ๋ฐํ์์ ์ค์ ๋์ ๊ตฌํ
- ์ค์ ๊ตฌํ์ฒด๊ฐ ํ์ํ ๋
- NestJS์ ๋ฐ์ฝ๋ ์ดํฐ ์ฌ์ฉ์ด ํ์ํ ๋
- ์ํ์ ํ์๋ฅผ ํจ๊ป ๊ด๋ฆฌํ ๋
- DI ์์คํ ์์ ์ฃผ์ ํ ๋์์ผ ๋
๋๋ ๊ณต๋ถํ๋ฉด์ ์๊ฒ ๋ ๋ด์ฉ์ ์ ๋ฆฌํ์ ๋ฟ ๊ฒฐ๊ตญ ๊ฒฝํ์ด ์ข ๋ ์์ฌ์ผ ์ํฉ์ ๋ง๊ฒ ์ ์ ํ๊ฒ ๋๊ตฌ๋ฅผ ์ ํํ ์ ์๊ฒ ๋ ๊ฒ ๊ฐ๋ค. ํ์ฌ ์์ ์ค์ธ ํ๋ก์ ํธ๋ง ํ๋๋ผ๋ ๊ทธ๋ฅ ์๋ฌด๋ ๊ฒ๋ ํด๋์ค๋ฅผ ๋จ๋ฐํ๊ณ ์์ผ๋.. ๊ตฌํ์ด ์์ฑ๋๋ฉด ๊ณต๋ถํ ๋ด์ฉ์ ํ ๋๋ก ๊ตฌ์กฐ๋ฅผ ์ ์ฒด์ ์ผ๋ก ์์ ํด ์ฃผ์ด์ผ๊ฒ ๋ค๊ณ ์๊ฐํ๊ณ ์๋ค.
์ค์ ๊ฒฝํ์ด ์๋ ๊ฐ๋ฐ์์ ๋ธ๋ก๊ทธ์์๋ ๊ธฐ๋ณธ์ ์ผ๋ก Interface๋ก ์ ์ํ๊ณ , ๋ณต์กํ ํ์ ์ด๋ ๋ณํ์ด ํ์ํ ๋๋ type์ ์ฐ๊ณ , ์ค์ ๊ตฌํ์ด ํ์ํ ๊ฒฝ์ฐ class๋ฅผ ์ฌ์ฉํ๋ ๊ฒ ํจ๊ณผ์ ์ด๋ผ๊ณ ํ๋ค.
์ถ์ฒ
'Framework > Nest.js' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[NestJS] Middleware, Filters , Guards, Interceptors ๋น๊ต (0) | 2025.03.10 |
---|---|
[NestJS] - NestJS์ Module, Providers, Controlller ์์๋ณด๊ธฐ (0) | 2025.03.05 |