0
0
NestjsHow-ToBeginner ยท 3 min read

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:

  • nest is the Nest CLI command.
  • new tells the CLI to create a new project.
  • project-name is 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-name
๐Ÿ’ป

Example

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-app
Output
โœ” 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 nest command 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 start inside the project folder to start the server
  • Use nest generate commands 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.