Projektstruktur und CLI
Lernen Sie, ein neues NestJS-Projekt mit der CLI zu initialisieren, die standardmäßige Ordnerstruktur zu verstehen und Komponenten effizient zu generieren.
Projektstruktur und CLI ist eine kostenlose NestJS Enterprise Backend APIs-Lektion auf CoddyKit. Dies ist Lektion 2 von 3. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des NestJS Enterprise Backend APIs-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der NestJS Enterprise Backend APIs-Kurs umfasst insgesamt 3 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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.
Häufig gestellte Fragen
Ist die Lektion „Projektstruktur und CLI“ kostenlos?
Ja — der vollständige Text von „Projektstruktur und CLI“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des NestJS Enterprise Backend APIs-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der NestJS Enterprise Backend APIs-Kurs umfasst insgesamt 3 Lektionen.
Was lerne ich in „Projektstruktur und CLI“?
Lernen Sie, ein neues NestJS-Projekt mit der CLI zu initialisieren, die standardmäßige Ordnerstruktur zu verstehen und Komponenten effizient zu generieren. Du übst NestJS Enterprise Backend APIs mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um NestJS Enterprise Backend APIs zu starten?
Keine Vorkenntnisse erforderlich. NestJS Enterprise Backend APIs auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 3.
Wie lange dauert die Lektion „Projektstruktur und CLI“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser NestJS Enterprise Backend APIs-Lektion Code schreiben und ausführen?
Ja. Jede NestJS Enterprise Backend APIs-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Einführung in das NestJS-Framework
- Projektstruktur und CLI
- Module, Controller und Services