A practical guide covering the complete installation process through to your first functional project
TL;DR: This guide lays out everything about Node.js and npm in one place. If you're using AI to write code (hello, vibe coders!), you might end up with a project you need to build but no npm installed. Here's what to install, what alternatives you have, what goes wrong and how to fix it + plus some senior dev tips.
IMPORTANT!
If you don't want to install anything and want to build everything in the cloud, you can skip the first part of the article until the Cloud Building heading.
Introduction
Node.js is basically JavaScript running outside the browser — on your computer, a server, whatever.
npm (Node Package Manager) comes with Node.js and lets you:
- Grab thousands of libraries off the shelf
- Keep track of versions
- Run build scripts
- Publish your own packages
Methods for Installing Node.js on Windows
The selection of an installation method should be based on what you are doing. For isolated or one-time usage scenarios, the official installer is OK. For ongoing development activities, NVM or Chocolatey are much better.
Installation via Official Installer
Step 1: Downloading
- Go to https://nodejs.org/
- Download the LTS version (Long Term Support) — it's more stable
- Run the
.msiinstaller - Agree to everything.
- npm is usually added to PATH automatically
- Then you need to verify:
node --version
# Should output: v20.x.x or v18.x.x
npm --version
# Should output: 10.x.x
Why It's Good
Easy peasy... Download LTS, click "Next" a bunch of times — boom, you've got Node.js. Easy if you don't want to mess with setup.
Why It Sucks
- Updating means downloading a whole new installer
- Can't run different versions side by side
- Stuck with what you installed
FOR VIBE CODERS: If AI generated code for a newer version of Node.js and you have an old one — there will be errors.
P.S. NVM solves this problem. Check section Installation via NVM.
Installation via Chocolatey
What's Chocolatey?
Windows package manager. Like apt-get on Linux. Install once, then everything via commands.
What You Need First
Get Chocolatey (if missing):
Run PowerShell as admin:
# Check if choco is installed
choco --version
# If not, install:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Install Node.js
# Install latest LTS
choco install nodejs-lts -y
# Specific version
choco install nodejs --version=20.11.0 -y
# Update
choco upgrade nodejs-lts
# Uninstall
choco uninstall nodejs
Why It's Good
Big upsides:
- Easy updates:
choco upgrade nodejs-lts - One command to uninstall
- Adds to PATH automatically
- Install any program this way
Installation via Winget
Windows 10 (1809+) and Windows 11 have a built-in package manager — Winget. No additional installation needed.
Commands
# Search available versions
winget search nodejs
# Install LTS version
winget install OpenJS.NodeJS.LTS
# Install latest (non-LTS)
winget install OpenJS.NodeJS
# Update
winget upgrade OpenJS.NodeJS.LTS
# Uninstall
winget uninstall OpenJS.NodeJS
Installation via NVM (Recommended for Developers)
NVM (Node Version Manager) is the standard in the Node.js development world. Allows you to have multiple versions of Node.js simultaneously and switch between them with a single command.
Especially useful when:
- Old project requires Node.js 16, while new one requires Node.js 20
- Testing compatibility across different versions
- Gradually updating the version
Option 1: NVM for Windows
- Download from: https://github.com/coreybutler/nvm-windows/releases
- Install
nvm-setup.exe - Open a new terminal
NVM Commands (for Windows)
IMPORTANT! NVM commands for Linux/Mac do not work on Windows. NVM for Windows has different syntax.
IMPORTANT! For the
nvm usecommand to work, the terminal must be run as Administrator, or Developer Mode must be enabled in Windows (Settings -> Privacy & security -> For developers). Otherwise, Windows will block symlink creation and the Node.js version won't switch.
# Install specific version (MUST specify!)
nvm install 20
nvm install 18
nvm install 20.11.0
# Install latest available version (NOT lts!)
nvm install latest
# View installed versions
nvm list
# Use a specific version
nvm use 20
# Note: nvm alias default does NOT work on Windows!
# The version selected via nvm use becomes active automatically
# Uninstall a version
nvm uninstall 18
Option 2: Volta (Modern Alternative)
FOR VIBE CODERS: Volta is a relatively new tool. It automatically detects the required Node.js version for a project (reads from package.json). Very convenient if you often download other people's projects.
# Install Volta
winget install Volta.Volta
# Install Node.js
volta install node
# Install specific version
volta install node@20
# Pin version for project
volta pin node@20
IMPORTANT for Windows: For Volta to work correctly, you must enable Developer Mode in Windows settings. This allows the utility to create symlinks without requesting administrator rights.
P.S. An extra benefit is that Volta is one of the fastest Node.js version managers.
Check It Works
⚠️ Don't skip this! 10 seconds now saves hours of debugging.
PowerShell or CMD
# Check versions
node --version
npm --version
# Shorter way
node -v
npm -v
# Where npm lives
npm config get prefix
If It Doesn't Work
Most common issue: system can't find Node.js. Quick fix:
- Restart terminal — PATH needs a new window
- Check PATH manually:
System → Advanced → Environment Variables
Look for:
C:\Program Files\nodejs\
or
%APPDATA%\npm
- Reinstall with "Add to PATH" checked
Basic npm Commands
npm is your main tool for Node.js. These are the everyday commands you'll use constantly.
Starting a Project
# Create new package.json (interactively)
npm init
# Create with default settings
npm init -y
# Create with all parameters specified
npm init --yes
Run npm init -y and you get a basic package.json. Think of it like "new document" in Word — your project's starting point.
Installing Dependencies
# Install all dependencies from package.json
npm install
# or shorthand
npm i
# Install specific package
npm install <package-name>
npm i <package-name>
# Install as development dependency (devDependencies)
npm install <package-name> --save-dev
npm i <package-name> -D
# Install globally (available everywhere in system)
npm install -g <package-name>
# Install specific version
npm install lodash@4.17.21
npm i express@4.18.2
IMPORTANT!
Global packages (-g) will bite you in big projects. They create system-specific dependencies. Always install locally in your project.
Managing Packages
# Update all packages
npm update
# Remove package
npm uninstall <package-name>
npm remove <package-name>
# Show globally installed packages
npm list -g --depth=0
# Show project's installed packages
npm list
Running Scripts
# Run script from package.json
npm run <script-name>
# Run standard scripts (start, test, build)
npm start
npm test
npm run build
Useful Flags
# Install without saving to package.json
npm install <package> --no-save
# Install only production dependencies
npm install --production
# Show outdated packages
npm outdated
# Security audit
npm audit
npm audit fix
Cache and Cleaning
# Clear npm cache
npm cache clean --force
# Delete node_modules and reinstall
# Safe deletion in Windows (bypasses path length limit):
npx rimraf node_modules
npm install
Building a Project
FOR VIBE CODERS: Typical scenario: AI wrote a software, there's a package.json, and you don't know what to do. Answer:
npm install→npm run build.
Typical package.json Structure
{
"name": "my-project",
"version": "1.0.0",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"dev": "tsc -w",
"start": "node dist/index.js",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"express": "^4.18.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"typescript": "^5.3.0"
}
}
Typical Build Scripts
# Install dependencies
npm install
# Build project
npm run build
# Development mode (watch - automatic rebuild)
npm run dev
# Run in development mode with nodemon
npm run dev:watch
Build Result
After npm run build:
- TypeScript compiles to JavaScript
- Files appear in the
dist/folder - Ready-to-use code can be deployed
P.S. dist/ is the standard name for the compiled code folder (from "distribution"). It's usually what goes to production.
Alternative Package Managers
npm is not the only option. Yarn and pnpm have their own advantages.
Yarn
# Enable corepack (built into Node.js)
corepack enable
# Activate stable yarn version
corepack prepare yarn@stable --activate
# Initialize project
yarn init
# Install dependencies
yarn
yarn add <package>
yarn add <package> -D
# Build
yarn build
Yarn advantages:
- Faster than npm (caches packages)
- Prettier console output
- Built-in yarn.lock (equivalent to package-lock.json)
In my opinion, there's no major difference between npm and Yarn, you can choose what you like better.
pnpm
# Enable corepack and activate pnpm
corepack enable
corepack prepare pnpm@latest --activate
# Use
pnpm install
pnpm add <package>
pnpm run build
pnpm advantages:
- Saves disk space (symlinks)
- Faster than npm and yarn
- Dependency isolation (better for monorepos)
IMPORTANT!
pnpm uses content-addressable storage. One physical file = many symbolic links. This really saves space — sometimes 3-4x.
Disadvantages: Not all projects work correctly with pnpm due to different node_modules structure.
Building in the Cloud
Need to build but Node.js isn't on the machine? Using someone else's computer? Cloud is the easy answer.
Option 1: GitHub Codespaces
- Open repo on GitHub
- Click "Code" → "Codespaces"
- Spin up a new codespace
- In the terminal:
npm install
npm run build
Plus: Free for personal use, nothing to install.
Option 2: StackBlitz
- Head to https://stackblitz.com/
- Create new project
- Upload files (drag & drop)
- Terminal:
npm install
npm run build
Option 3: Gitpod
- Go to https://gitpod.io/
- Paste your repo URL
- Dev environment opens automatically
GitHub Actions for Automated Builds
IMO the simplest (and correct) way is CI/CD automation. You push code, GitHub itself builds the project and checks that nothing broke.
Why?
- Build runs automatically on push
- Can build under different Node.js versions
- Artifacts are saved in Release
- Automated tests
Workflow Example
Create file .github/workflows/build.yml:
name: Build
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.node-version }}
path: dist/
P.S. Today, GitHub Actions is one of the most popular CI/CD tools. According to surveys, more than 70% of developers use it for build and test automation.
More Complex Example with Release
name: Release
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install and Build
run: |
npm ci
npm run build
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: dist/**
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
How to Run Build Locally (act)
SENIOR GOTCHA!
act requires Docker Desktop to be installed! Without Docker, the act command will just fail with an error. On Windows, Docker setup is a separate task, be prepared for this.
# Install act
choco install act -y
# Run workflow locally
act
You could say that act is "GitHub Actions locally." Run it — and you have your own personal CI/CD on your computer with blackjack and... oops.
Troubleshooting
90% of Node.js stuff fixes by restarting terminal, clearing cache, or switching versions. Here's the rest.
npm install slow
Most common issue, especially on Windows.
Fixes:
# Use npm ci instead (faster, uses lockfile)
npm ci
# Clear cache
npm cache clean --force
# Switch to faster manager
npm install -g pnpm
pnpm install
Out of memory
# Bump memory (PowerShell)
$env:NODE_OPTIONS = "--max_old_space_size=4096"
npm run build
Permission denied
Windows + perms = pain. Run terminal as admin.
Or move npm folder:
# Global packages in user dir (PowerShell)
mkdir "$env:USERPROFILE\npm-global"
npm config set prefix "$env:USERPROFILE\npm-global"
# Add to PATH
That's it! Covered the main stuff.
Thanks for reading! Subscribe, like, feedback = more good content. Thanks!
Top comments (0)