How to Create a NestJS Project: Step-by-Step Guide
To create a NestJS project, first install the Nest CLI using
npm i -g @nestjs/cli. Then run nest new project-name to generate a new project with all necessary files and dependencies.Syntax
The basic command to create a new NestJS project is nest new project-name. Here:
nestis the Nest CLI command.newtells the CLI to create a new project.project-nameis the folder name for your new project.
Before running this, you need to install the Nest CLI globally with npm i -g @nestjs/cli.
bash
npm i -g @nestjs/cli
nest new project-nameExample
This example shows how to create a new NestJS project called my-nest-app. The CLI will ask you to choose a package manager and then install dependencies automatically.
bash
npm i -g @nestjs/cli
nest new my-nest-appOutput
โ Creating project my-nest-app
โ Installing dependencies
โ Successfully created project my-nest-app
Common Pitfalls
Some common mistakes when creating a NestJS project include:
- Not installing the Nest CLI globally first, causing
nestcommand not found errors. - Choosing an unsupported package manager or not having one installed.
- Running the command in a folder without write permissions.
Always ensure Node.js and npm are installed and updated before starting.
bash
Wrong: nest new my-app # Error: 'nest' is not recognized Right: npm i -g @nestjs/cli nest new my-app
Quick Reference
Summary tips for creating a NestJS project:
- Install Nest CLI globally:
npm i -g @nestjs/cli - Create project:
nest new project-name - Choose your package manager when prompted (npm or yarn)
- Run
npm run startinside the project folder to start the server - Use
nest generatecommands to add modules, controllers, and services
Key Takeaways
Install the Nest CLI globally before creating a project using npm.
Use the command 'nest new project-name' to generate a new NestJS project.
Choose a package manager when prompted to install dependencies automatically.
Run 'npm run start' inside the project folder to launch the NestJS server.
Avoid running commands without proper permissions or missing Node.js/npm installations.