NestJS Setupπ± Beginner
NestJS provides a tremendously powerful CLI (Command Line Interface) that automates the creation of your project and generates all your boilerplate files instantly.
What is the Nest CLI?
The Nest CLI is an official NPM tool that scaffolds the strict folder structure NestJS requires. Instead of manually creating controllers, services, and modules (and wiring them all together), the CLI does it perfectly in seconds.
Why Not Build it Manually?
Because NestJS relies heavily on Dependency Injection, creating a new feature requires updating multiple arrays in a Module file. Doing this manually is highly prone to human error (like forgetting to export a service). The CLI guarantees flawless execution.
How to Install and Create
First, install the CLI globally on your machine:
# Install the CLI globally (-g)
npm i -g @nestjs/cliNow, generate a brand new backend API:
# Scaffold a new project named 'my-api'
nest new my-api
# Navigate in
cd my-api
# Start the server in watch mode (auto-reloads on save!)
npm run start:devYour enterprise backend is now running on http://localhost:3000.
nest generate command. Typing nest g resource users will instantly create a full CRUD (Create, Read, Update, Delete) module for 'users', complete with Controllers, Services, and testing files!