0Pricing
NestJS Enterprise Backend APIs · Урок

Структура проекта и CLI

Научитесь инициализировать новый проект NestJS с помощью CLI, разберитесь в структуре папок по умолчанию и эффективно создавайте компоненты.

«Структура проекта и CLI» — бесплатный урок NestJS Enterprise Backend APIs на CoddyKit. Это урок 2 из 3. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения NestJS Enterprise Backend APIs, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс NestJS Enterprise Backend APIs содержит 3 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

NestJS CLI: Your Development Ally

The NestJS CLI is your dev assistant — it scaffolds projects, generates boilerplate for modules and services, and runs your builds.

Get the CLI Up and Running

Install the CLI globally with npm i -g @nestjs/cli (Node and npm required first). The -g flag makes the nest command available everywhere.

Starting a New NestJS App

Create a project with nest new my-first-backend. The CLI asks for a package manager, then sets up files, dependencies, and boilerplate.

Understanding the Project Layout

A new project's layout: src/ holds your code, node_modules/ the dependencies, test/ e2e tests, and dist/ the compiled output.

Core Application Files in `src`

Inside src/ are the core files: main.ts bootstraps the app, app.module.ts is the root module, plus a starter controller and service.

`main.ts`: Application Entry Point

main.ts is the entry point: NestFactory.create() builds the app and app.listen() starts the server, usually on port 3000.

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(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();

Building Blocks: A Simple Class

NestJS runs on classes — controllers, services, and modules are all TypeScript classes. This runnable snippet shows the basic class structure.

class Greeter {
  name: string;

  constructor(name: string) {
    this.name = name;
  }

  greet(): string {
    return `Hello, ${this.name}! Welcome to CoddyKit.`;
  }
}

// This is the entry point for running the example
function main() {
  const greeter = new Greeter("NestJS Learner");
  console.log(greeter.greet());
}

main();

Streamline with `nest generate`

As the app grows, use nest generate (or nest g) to scaffold modules, controllers, services, guards, pipes — and auto-wire them in.

CLI in Action: New Module

For a Users feature, run nest g module users. The CLI creates the folder and users.module.ts, then registers it in your root AppModule.

Test Your CLI Knowledge

You've learned about the NestJS CLI and how it helps set up and structure your project.

Which CLI command is used to quickly create a new NestJS project named my-api?

Summary: CLI & Project Setup

You used the CLI: installed it, created a project with nest new, explored the layout, and scaffolded components with nest generate.

Часто задаваемые вопросы

Урок «Структура проекта и CLI» бесплатный?

Да — полный текст урока «Структура проекта и CLI» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс NestJS Enterprise Backend APIs, подпишись на CoddyKit PRO. Курс NestJS Enterprise Backend APIs содержит 3 уроков всего.

Чему я научусь в уроке «Структура проекта и CLI»?

Научитесь инициализировать новый проект NestJS с помощью CLI, разберитесь в структуре папок по умолчанию и эффективно создавайте компоненты. Ты практикуешь NestJS Enterprise Backend APIs с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать NestJS Enterprise Backend APIs?

Предыдущий опыт не требуется. NestJS Enterprise Backend APIs на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 2 из 3.

Сколько времени занимает урок «Структура проекта и CLI»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке NestJS Enterprise Backend APIs?

Да. Каждый урок NestJS Enterprise Backend APIs включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Введение во фреймворк NestJS
  2. Структура проекта и CLI
  3. Модули, контроллеры и сервисы
← Назад к NestJS Enterprise Backend APIs