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 usenestcommands anywhere.nest new project-name: Creates a new NestJS project with the given name.
bash
npm i -g @nestjs/cli
nest new project-nameExample
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-appOutput
โ 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.jsinstalled or using an outdated version (NestJS requires Node.js 14 or higher). - Forgetting to install the CLI globally, which makes
nestcommands unavailable. - Running
nest newwithout 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/clito install CLI globally. - Run
nest new project-nameto create a new project. - Ensure Node.js version is 14 or higher.
- Use
npm run startinside 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.