Understanding Node.js: What You Need to Know First
What is Node.js and Why Use It?
Node.js is a free, open‑source JavaScript runtime built on Google’s V8 engine. It lets you execute JavaScript outside a web browser, giving you access to the file system, network sockets, and OS processes. This makes it ideal for building web servers, APIs, CLI tools, and automation scripts.
LTS vs. Current Versions: Which One Should You Choose?
Node follows a predictable release cadence:
- LTS (Long‑Term Support) – even‑numbered releases (e.g., 22.x). They receive security patches and bug fixes for roughly 30 months. Best for production, learning, and any project where stability matters.
- Current – odd‑numbered releases (e.g., 23.x). They bring the newest language features and performance tweaks but are supported for only ~6 months. Use them for experimenting or when a feature is missing from LTS.
As of 2026, the active LTS line is v22.6.0 and the latest Current release is v23.2.0.
System Prerequisites and Requirements
Hardware and OS Compatibility
Node runs on virtually every modern platform. Verify the following before you begin:
| OS | Supported Architectures | Installer Type |
|---|---|---|
| Windows 10/11 | x64, ARM64 | .msi (official) or winget |
| macOS 13+ (Ventura, Sonoma) | x64, Apple Silicon (ARM64) | .pkg or Homebrew |
| Linux (Ubuntu 22.04+, Debian 12+, Fedora 38+, Arch) | x64, ARM64, ARMv7 | tarball, apt/yum, nvm |
If you are on an ARM‑based machine (Apple Silicon, Raspberry Pi, AWS Graviton), download the arm64 binary; using the x86 installer will cause crashes or severe performance loss.
Checking for Existing Installations
Open a terminal and run:
node --version
npm --version
If the commands return a version number, note it. You may need to remove the old binary before proceeding, especially when mixing installers (e.g., a Microsoft Store version with the official MSI).
How to Set Up Node.js: Detailed Installation Methods
Method 1: Using the Official Installer (Beginner Friendly)
- Visit nodejs.org and click the LTS
v22.6.0Windows/macOS installer. - Download the accompanying
SHA256SUMSfile. - Open PowerShell (or Terminal on macOS) and verify the checksum:
Get-FileHash -Algorithm SHA256 .\node-v22.6.0-x64.msi | Format-List
# Compare the output with the value in SHA256SUMS
- Run the MSI (or .pkg) and accept the defaults. The installer adds
C:\Program Files\nodejsto%PATH%automatically. - Restart your terminal, then confirm:
node -v # should print v22.6.0
npm -v # should print a 9+ version
npx -v # bundled with npm, prints the same version
Method 2: Using NVM (Node Version Manager) for Advanced Control
nvm works on macOS and Linux. It stores each Node version in ~/.nvm, removing the need for sudo and eliminating permission errors.
- Install nvm (the latest script supports ARM and x86):
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# Then load it
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
- Install the LTS version and set it as default:
nvm install --lts # pulls v22.6.0
nvm alias default 22
nvm use default
- Verify:
node -v
npm -v
For per‑project version pinning, add a .nvmrc file containing the desired version (e.g., 22.6.0). When you cd into the folder, run nvm use and the correct binary is automatically selected.
Method 3: Installing Node.js via Package Managers (Homebrew, APT, Yum)
Package managers keep Node up‑to‑date with a single command, but they usually install the system‑wide version, which can re‑introduce permission traps.
- macOS (Homebrew):
brew update
brew install node@22 # installs the LTS formula
brew link --overwrite --force node@22
- Ubuntu/Debian (APT) – use the official NodeSource repo for the latest LTS:
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
- Fedora/CentOS (Yum/DNF):
curl -fsSL https://rpm.nodesource.com/setup_22.x | sudo bash -
sudo dnf install -y nodejs
Verifying Your Installation via Terminal
Run the three smoke‑test commands below in a fresh session:
node -v # e.g., v22.6.0
npm -v # e.g., 9.9.2
npx -v # same as npm version
node -e "console.log('Node works!')"
If any command fails, double‑check your PATH variable and whether multiple Node installations are conflicting.
Best Practices for a Stable Development Environment
Configuring Your Global NPM Directory
Running npm install -g with a system‑wide Node often triggers EACCES errors. Fix it once by moving the global directory to your home folder:
mkdir "${HOME}/.npm-global"
npm config set prefix "${HOME}/.npm-global"
# Add to PATH (bash/zsh)
echo 'export PATH="${HOME}/.npm-global/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Setting Up a Code Editor (VS Code Integration)
Visual Studio Code ships with built‑in debugging for Node. Install the Node.js Extension Pack from the marketplace, then enable the “Run on Save” feature:
# In settings.json
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"javascript.validate.enable": false # let ESLint handle linting
Managing Environment Variables
Some corporate networks require a proxy. Configure npm once:
npm config set proxy http://proxy.mycorp.com:8080
npm config set https-proxy http://proxy.mycorp.com:8080
If you need to point Node to custom modules, set NODE_PATH:
export NODE_PATH="${HOME}/my-shared-modules"
Common Installation Mistakes and Troubleshooting
Fixing “Command Not Found” Errors
These usually stem from a broken PATH. On Windows, open System Properties → Environment Variables** and ensure C:\Program Files\nodejs\ appears before any other Node paths (e.g., Chocolatey). On macOS/Linux, add the correct bin folder to ~/.bashrc or ~/.zshrc and reload the shell.
Resolving Permission Issues with NPM
Never use sudo npm install -g. Instead:
- Switch to a user‑space global directory (see “Configuring Your Global NPM Directory”).
- If you already ran a sudo install, clean up the ownership:
sudo chown -R $(whoami) /usr/local/lib/node_modules
Handling Version Conflicts
If node -v shows a different version than you expect, run which node (Linux/macOS) or where node (Windows) to locate the binary. Remove or rename the unwanted executable and reinstall via your preferred method.
Verifying Binary Integrity with SHA‑256
Always compare the checksum before executing a downloaded installer:
# Example on macOS/Linux
curl -O https://nodejs.org/dist/v22.6.0/node-v22.6.0-linux-x64.tar.xz
curl -O https://nodejs.org/dist/v22.6.0/SHASUMS256.txt
sha256sum -c SHASUMS256.txt # should output “OK”
Docker‑Based Installation (Alternative for CI/CD)
When you need a reproducible environment, pull the official Node image:
docker pull node:22-alpine # lightweight LTS
docker run -it --rm node:22-alpine node -v
For CI pipelines, use the same image tag to guarantee identical Node version across builds.
Which Installation Path is Right for You?
Comparison Table: Personas vs. Recommended Setup
| User Profile / Target Persona | Recommended Choice / Approach | Key Reason & Benefits |
|---|---|---|
| Beginner / Student | Official MSI/PKG installer (LTS) | Zero‑config, graphical wizard, immediate access to node and npm. |
| Power User / Freelancer | nvm (or fnm) with .nvmrc per project | Instantly switch between LTS and Current, avoid sudo, keep projects isolated. |
| Enterprise / DevOps Engineer | Docker image or package‑manager install locked to LTS version | Immutable runtime, easy to version‑pin in CI/CD, integrates with orchestration tools. |
| Budget Hunter / Low‑Spec Device (Raspberry Pi) | ARM64 tarball + manual PATH setup | No extra runtime overhead, works on limited memory and storage. |