Struttura del progetto e CLI
Impari a inizializzare un nuovo progetto NestJS tramite la CLI, comprenda la struttura predefinita delle cartelle e generi componenti in modo efficiente.
Struttura del progetto e CLI è una lezione NestJS Enterprise Backend APIs gratuita su CoddyKit. Questa è la lezione 2 di 3. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento NestJS Enterprise Backend APIs, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso NestJS Enterprise Backend APIs include 3 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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.
Impara TypeScript con un tutor IA — gratis
Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.
- Corsi
- 20
- Lezioni
- 76
Domande Frequenti
La lezione «Struttura del progetto e CLI» è gratuita?
Sì — il testo completo di «Struttura del progetto e CLI» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso NestJS Enterprise Backend APIs, passa a CoddyKit PRO. Il corso NestJS Enterprise Backend APIs include 3 lezioni in totale.
Cosa imparerò in «Struttura del progetto e CLI»?
Impari a inizializzare un nuovo progetto NestJS tramite la CLI, comprenda la struttura predefinita delle cartelle e generi componenti in modo efficiente. Eserciti NestJS Enterprise Backend APIs con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare NestJS Enterprise Backend APIs?
Non è richiesta alcuna esperienza precedente. NestJS Enterprise Backend APIs su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 3.
Quanto tempo richiede la lezione «Struttura del progetto e CLI»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione NestJS Enterprise Backend APIs?
Sì. Ogni lezione NestJS Enterprise Backend APIs include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Introduzione al framework NestJS
- Struttura del progetto e CLI
- Moduli, controller e servizi