How to Install NestJS: A Complete Setup Guide for Node.js Developers
NestJS has become one of the most popular frameworks for building scalable server-side applications with Node.js. Built on top of Express (or optionally Fastify), it uses TypeScript by default and borrows heavily from Angular's architecture — making it a natural fit for developers who like structure, decorators, and modular design. Getting it installed correctly depends on a few key factors in your environment.
What You Need Before Installing NestJS
NestJS is a Node.js framework, so your machine needs Node.js installed before anything else works. Specifically:
- Node.js — version 16 or higher is generally recommended. NestJS actively tracks LTS (Long-Term Support) releases, so running an outdated Node version is one of the most common reasons the install fails or behaves unexpectedly.
- npm (comes bundled with Node.js) or an alternative package manager like Yarn or pnpm
- A terminal or command-line interface
- Optionally: a code editor like VS Code, which has strong TypeScript tooling
You can check your current Node.js version by running:
node -v And your npm version with:
npm -v If Node isn't installed, download it from the official Node.js website and install the LTS version for your operating system.
Installing the NestJS CLI
The cleanest way to start a NestJS project is through the NestJS CLI — a command-line tool that scaffolds your project structure, generates modules, controllers, services, and more.
Install it globally using npm:
npm install -g @nestjs/cli Or with Yarn:
yarn global add @nestjs/cli The -g flag installs the CLI globally, meaning you can use it across any project on your machine without reinstalling it each time.
Once installed, verify it worked:
nest --version If you see a version number returned, the CLI is ready. 🎉
Creating Your First NestJS Project
With the CLI installed, creating a new project takes a single command:
nest new project-name Replace project-name with whatever you want to call your application. The CLI will then:
- Ask you to choose a package manager (npm, Yarn, or pnpm)
- Scaffold a full project directory with a sensible default structure
- Automatically install all required dependencies
The generated folder structure looks like this:
project-name/ ├── src/ │ ├── app.controller.ts │ ├── app.module.ts │ ├── app.service.ts │ └── main.ts ├── test/ ├── package.json ├── tsconfig.json └── nest-cli.json The entry point is main.ts, which bootstraps the application. The app.module.ts file is the root module — the starting point for NestJS's dependency injection system.
Running the Application Locally
Once the project is created, navigate into the folder and start the development server:
cd project-name npm run start:dev The start:dev script runs the app with watch mode enabled — meaning it automatically restarts when you save file changes. By default, NestJS listens on port 3000, so you can open a browser and visit http://localhost:3000 to confirm it's running.
Installing NestJS Without the CLI
Some developers prefer to set up projects manually or add NestJS to an existing Node.js application. In that case, you install the core packages directly:
npm install @nestjs/core @nestjs/common rxjs reflect-metadata You'll also need to configure TypeScript manually by adding a tsconfig.json and enabling experimentalDecorators and emitDecoratorMetadata — both required for NestJS's decorator-based architecture to function.
This path gives you more control but requires a deeper understanding of how NestJS modules and dependency injection are wired together.
Key Variables That Affect Your Setup Experience
No two installs are identical. Several factors shape what you encounter:
| Variable | How It Affects the Install |
|---|---|
| Node.js version | Outdated versions cause peer dependency conflicts or missing features |
| Package manager | npm, Yarn, and pnpm handle lockfiles and hoisting differently |
| Operating system | Windows users may hit path or permission issues; Unix-based systems tend to be smoother |
| Global vs local CLI | Global installs can conflict if multiple projects use different NestJS versions |
| TypeScript familiarity | NestJS defaults to TypeScript; JS-only setups require additional configuration |
Common Install Issues and What Causes Them
- Permission errors on global install — On macOS/Linux, you may need to prefix the command with
sudo, or better yet, configure npm to use a user-owned directory to avoid this entirely nestcommand not found after install — Your system's PATH may not include the global npm bin directory; this is especially common on certain Linux distributions- Peer dependency warnings — These often appear when your Node or npm version doesn't align with what NestJS packages expect; upgrading Node usually resolves them 🔧
- TypeScript compilation errors on first run — Missing
tsconfig.jsonsettings, particularlyexperimentalDecorators: true, are the usual culprit in manual setups
How Your Use Case Changes the Approach
A developer building a REST API from scratch on a clean machine will follow the standard CLI path without friction. Someone integrating NestJS into a monorepo may use the CLI's built-in monorepo mode (nest new with workspace configuration). A team running Docker-based development environments will likely skip global CLI installs entirely and manage NestJS as a local dev dependency to keep environments consistent.
Developers coming from an Express background often appreciate that NestJS wraps Express under the hood — but the architectural patterns (modules, providers, decorators) represent a real learning curve that affects how much configuration feels intuitive versus unfamiliar.
The right installation path, and the right amount of scaffolding, depends on what you're building, how your team works, and how much structure you actually want NestJS to enforce on your project.