0
0
NestjsHow-ToBeginner ยท 3 min read

How to Install NestJS: Step-by-Step Guide

To install nestjs, first ensure you have Node.js and npm installed. Then run npm i -g @nestjs/cli to install the NestJS CLI globally, which helps you create and manage NestJS projects easily.
๐Ÿ“

Syntax

Use the following command to install the NestJS CLI globally on your system:

  • npm i -g @nestjs/cli: Installs the NestJS command line interface globally so you can use nest commands anywhere.
  • nest new project-name: Creates a new NestJS project with the given name.
bash
npm i -g @nestjs/cli
nest new project-name
๐Ÿ’ป

Example

This example shows how to install the NestJS CLI globally and create a new project called my-nest-app. It demonstrates the basic setup to start building with NestJS.

bash
npm i -g @nestjs/cli
nest new my-nest-app
Output
โœ” Package manager: npm โœ” Creating a new Nest project โœ” Installing dependencies Project setup complete. To get started: cd my-nest-app npm run start
โš ๏ธ

Common Pitfalls

Common mistakes when installing NestJS include:

  • Not having Node.js installed or using an outdated version (NestJS requires Node.js 14 or higher).
  • Forgetting to install the CLI globally, which makes nest commands unavailable.
  • Running nest new without a package manager installed (npm or yarn).

Always check your Node.js and npm versions with node -v and npm -v before installing.

bash
Wrong:
npm i @nestjs/cli
# This installs CLI locally, so 'nest' command won't work globally

Right:
npm i -g @nestjs/cli
# Installs CLI globally for easy use
๐Ÿ“Š

Quick Reference

Summary tips for installing NestJS:

  • Use npm i -g @nestjs/cli to install CLI globally.
  • Run nest new project-name to create a new project.
  • Ensure Node.js version is 14 or higher.
  • Use npm run start inside your project to run the app.
โœ…

Key Takeaways

Install NestJS CLI globally using npm i -g @nestjs/cli for easy project management.
Create new projects with nest new project-name command.
Ensure Node.js version 14 or higher is installed before starting.
Use npm run start inside your project folder to run the NestJS app.
Check your Node.js and npm versions to avoid installation issues.