모듈, 컨트롤러, 서비스
핵심 구성 요소를 깊이 있게 살펴봅니다. 모듈이 코드를 구성하고, 컨트롤러가 요청을 처리하며, 서비스가 비즈니스 로직을 캡슐화하는 방식을 학습합니다.
모듈, 컨트롤러, 서비스은(는) CoddyKit의 무료 NestJS Enterprise Backend APIs 강의입니다. 이것은 3개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 NestJS Enterprise Backend APIs 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. NestJS Enterprise Backend APIs 강의에는 총 3개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
NestJS Building Blocks
A NestJS app is built from three core blocks — Modules, Controllers, and Services — that organize code, handle requests, and hold logic.
Organizing with Modules
A Module (class with @Module()) is a feature group: it bundles related controllers and services and defines their dependency scope.
Your First NestJS Module
This AppModule shows the @Module() decorator declaring a controller and a service, making them available within its scope.
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [], // Other modules this module needs
controllers: [AppController], // Controllers handled by this module
providers: [AppService], // Services (providers) available in this module
exports: [], // Providers to export for other modules
})
export class AppModule {}Controllers: Handling Requests
Controllers (classes with @Controller()) handle incoming HTTP requests and return responses, delegating the heavy logic to services.
A Simple API Endpoint
This AppController uses @Get() to handle GET requests at /, calling AppService for the actual message.
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
@Controller() // Optional path prefix, e.g., '@Controller('users')'
export class AppController {
constructor(private readonly appService: AppService) {}
@Get() // Handles GET requests to '/' (or '/users' if prefix exists)
getHello(): string {
return this.appService.getHello();
}
}Services: Business Logic Hub
Services (providers marked @Injectable()) hold your business logic and DB calls — reusable units injected into controllers to keep them lean.
Your Logic in a Service
This AppService exposes a method for the controller to call. The @Injectable() decorator lets NestJS manage it via DI.
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello from NestJS!';
}
}Connecting the Dots
Dependency Injection wires it together: declare the parts in a module, ask for the service in the controller's constructor, and Nest injects it.
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
console.log('NestJS application is running on http://localhost:3000');
}
bootstrap();
// When you visit http://localhost:3000,
// AppController's getHello() is called,
// which in turn calls AppService's getHello().Component Roles Check
You've learned about Modules, Controllers, and Services. How well do you understand their primary roles?
Core Components Summary
You learned the core trio: Modules organize, Controllers handle requests, Services hold logic — all connected through DI. TypeORM next!
자주 묻는 질문
“모듈, 컨트롤러, 서비스” 강의는 무료인가요?
네 — “모듈, 컨트롤러, 서비스” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 NestJS Enterprise Backend APIs 강의 전체를 잠금 해제할 수 있습니다. NestJS Enterprise Backend APIs 강의에는 총 3개의 강의가 포함되어 있습니다.
“모듈, 컨트롤러, 서비스”에서 뭘 배우나요?
핵심 구성 요소를 깊이 있게 살펴봅니다. 모듈이 코드를 구성하고, 컨트롤러가 요청을 처리하며, 서비스가 비즈니스 로직을 캡슐화하는 방식을 학습합니다. 브라우저에서 직접 실행하는 실습 코드로 NestJS Enterprise Backend APIs을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
NestJS Enterprise Backend APIs을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 NestJS Enterprise Backend APIs은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 3개 중 3번째 강의입니다.
“모듈, 컨트롤러, 서비스” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 NestJS Enterprise Backend APIs 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 NestJS Enterprise Backend APIs 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- NestJS 프레임워크 소개
- 프로젝트 구조와 CLI
- 모듈, 컨트롤러, 서비스