0Pricing
NestJS Enterprise Backend APIs · درس

الوحدات ووحدات التحكم والخدمات

تعمّق في المكونات الأساسية: كيف تنظّم الوحدات الشيفرة، وتعالج وحدات التحكم الطلبات، وتغلف الخدمات منطق الأعمال.

الوحدات ووحدات التحكم والخدمات درس مجاني في NestJS Enterprise Backend APIs على CoddyKit. هذا هو الدرس 3 من أصل 3. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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) وفتح باقي دورة NestJS Enterprise Backend APIs، انتقل إلى CoddyKit PRO. تتضمن دورة NestJS Enterprise Backend APIs 3 دروس في المجموع.

ماذا ستتعلم في «الوحدات ووحدات التحكم والخدمات»؟

تعمّق في المكونات الأساسية: كيف تنظّم الوحدات الشيفرة، وتعالج وحدات التحكم الطلبات، وتغلف الخدمات منطق الأعمال. تتمرن على NestJS Enterprise Backend APIs مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ NestJS Enterprise Backend APIs؟

لا تُشترط خبرة سابقة. NestJS Enterprise Backend APIs على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 3.

كم من الوقت يستغرق درس «الوحدات ووحدات التحكم والخدمات»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس NestJS Enterprise Backend APIs هذا؟

نعم. كل درس في NestJS Enterprise Backend APIs يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. مقدمة إلى إطار NestJS
  2. بنية المشروع وCLI
  3. الوحدات ووحدات التحكم والخدمات
← العودة إلى NestJS Enterprise Backend APIs