Install Node.js first, then add Nest.js through npm
Nest.js is a framework for building server-side applications with JavaScript or TypeScript. Before you can use it, you need Node.js installed on your computer — Nest.js runs on top of Node.js and uses npm (Node Package Manager) to download and manage code libraries.
The installation process takes three steps: install Node.js if you don't have it, install the Nest CLI (command-line tool) globally on your machine, and then create a new Nest.js project. The whole process usually takes 10 to 15 minutes on a typical internet connection.
Key Takeaways
- You must install Node.js before Nest.js, because Nest.js depends on Node.js and npm to run.
- The Nest CLI is a command-line tool you install once globally, then use to create and manage Nest.js projects.
- After installation, you start a development server with npm run start to test your project locally.
- Windows, Mac, and Linux all follow the same installation steps, though the download page detects your operating system automatically.
Download and install Node.js
Go to nodejs.org and download the LTS (Long Term Support) version, which is the stable version recommended for most users. The website detects your operating system automatically and shows you the right download button.
Run the installer file after it downloads. On Windows, double-click the .msi file. On Mac, double-click the .pkg file. On Linux, follow the instructions for your distribution on the Node.js website. The installer walks you through setup — you can accept the default options for all screens.
After installation finishes, open a terminal or command prompt and type node --version. You should see a version number like v20.10.0. This confirms Node.js installed correctly. npm comes bundled with Node.js, so you don't install it separately.
Install the Nest CLI globally
Open a terminal or command prompt and run this command:
npm install -g @nestjs/cli
The -g flag means "global" — this installs the Nest CLI once on your computer, and you can use it from any folder. The installation downloads the Nest CLI package from npm's servers and sets it up so you can type nest commands in your terminal.
After it finishes, type nest --version to confirm the installation worked. You should see a version number like 10.2.8.
Create a new Nest.js project
In your terminal, navigate to the folder where you want to create your project. For example, if you want to create it on your Desktop, type cd Desktop. Then run:
nest new my-app
Replace my-app with whatever you want to name your project. The Nest CLI creates a new folder with that name and fills it with starter files and folders. It also runs npm install automatically to download all the libraries your project needs — this step takes a few minutes depending on your internet speed.
When the command finishes, type cd my-app to enter your project folder. You're now ready to start the development server.
Start the development server
Inside your project folder, run:
npm run start
This command starts a local development server on your computer. After a few seconds, you should see a message saying the server is listening on http://localhost:3000. Open that address in your web browser — you should see a message that says "Hello World!"
The development server watches for changes to your code files. When you save a file, the server automatically restarts and loads your changes. To stop the server, press Ctrl+C (or Cmd+C on Mac) in your terminal.
Understand the project structure
When you create a new Nest.js project, the CLI generates several folders and files. The src folder holds your application code — this is where you write the logic for your server. Inside src, you'll find main.ts, which starts your application, and app.module.ts, which organizes your code into modules.
The node_modules folder contains all the libraries your project depends on — you don't edit files in this folder. The package.json file lists which libraries your project uses and what commands you can run (like npm run start). The tsconfig.json file configures TypeScript, the language Nest.js uses by default.
You don't need to understand all of these files right away. Start by editing files in the src folder to build your application.
Troubleshooting common installation problems
If you see an error like "command not found: nest" after installing the Nest CLI, Node.js or npm may not be in your system's PATH. Try closing and reopening your terminal completely, then try the command again. If that doesn't work, uninstall the Nest CLI with npm uninstall -g @nestjs/cli and install it again.
If npm install fails while creating a new project, you may have a network issue or a problem with npm's cache. Try running npm cache clean --force, then run nest new my-app again. On Windows, you may need to run your terminal as Administrator for this to work.
If the development server won't start, make sure port 3000 isn't already in use by another application. You can change the port by editing main.ts in the src folder and changing the line await app.listen(3000) to a different number like 3001.
Frequently Asked Questions
Do I need to know TypeScript to use Nest.js?
Nest.js uses TypeScript by default, but you can write in plain JavaScript if you prefer. When you create a new project, you can choose JavaScript instead of TypeScript during setup. However, most Nest.js documentation and examples use TypeScript, so learning it will help you follow tutorials and find answers online.
Can I install Nest.js on Windows, Mac, and Linux the same way?
Yes. The installation steps are identical across all three operating systems. The only difference is the Node.js installer file you download — the nodejs.org website automatically detects your operating system and shows you the correct download.
What does the development server do?
The development server runs your Nest.js application locally on your computer so you can test it before publishing it to the internet. It watches your code files and automatically restarts when you make changes, so you can see your updates immediately without manually restarting anything.
Can I use a different port instead of 3000?
Yes. Edit the main.ts file in your src folder and change await app.listen(3000) to any port number you want, like 3001 or 8080. Make sure the port isn't already in use by another application on your computer.
What if I want to uninstall Nest.js?
To remove the Nest CLI, run npm uninstall -g @nestjs/cli. To delete a specific project, simply delete its folder. Uninstalling the Nest CLI doesn't affect projects you've already created — they will continue to work as long as Node.js is installed.