How to Install Node.js and npm on Windows Server 2012 R2
Node.js is the JavaScript runtime built on Chrome’s V8 engine, and npm is its package manager providing access to hundreds of thousands of open-source packages. Installing Node.js on Windows Server 2012 R2 enables you to run server-side JavaScript applications, build tools (Webpack, Gulp, Grunt), test runners (Jest, Mocha), and automation utilities. It also serves as a prerequisite for many modern development toolchains and CI/CD pipeline tools. This guide covers multiple installation methods, version management with nvm-windows, global package configuration, PATH setup, and integration with build automation on WS2012 R2.
Prerequisites
- Windows Server 2012 R2 with administrator access
- PowerShell 4.0
- At least 1 GB of free disk space
- Outbound HTTPS access to nodejs.org and registry.npmjs.org
- Visual C++ Build Tools (required for npm packages with native addons)
Step 1: Determine the Compatible Node.js Version
Node.js 18.x (LTS) requires Windows 8.1/Server 2012 R2 or later as the minimum supported platform. Node.js 20.x and 22.x also support WS2012 R2. However, some npm packages with native bindings require a specific Visual C++ runtime. For maximum compatibility on WS2012 R2:
- Node.js 18.x (Hydrogen LTS) — fully compatible, recommended for production
- Node.js 20.x (Iron LTS) — compatible with WS2012 R2
- Node.js 22.x — verify compatibility with your specific workload
Step 2: Install Node.js via MSI Installer
Download the Windows 64-bit MSI from the Node.js official website:
$NodeVersion = "18.20.4"
$NodeMSI = "node-v${NodeVersion}-x64.msi"
$DownloadUrl = "https://nodejs.org/dist/v${NodeVersion}/$NodeMSI"
New-Item -ItemType Directory -Path "C:Temp" -Force
Invoke-WebRequest -Uri $DownloadUrl -OutFile "C:Temp$NodeMSI"
Install silently. The MSI installer adds Node.js and npm to the system PATH automatically and installs npm globally:
Start-Process -FilePath "msiexec.exe" -ArgumentList `
"/i `"C:Temp$NodeMSI`"",
"/quiet /norestart",
"ADDLOCAL=NodeRuntime,npm,DocumentationShortcuts,EnvironmentPathNode" `
-Wait -PassThru
Write-Host "Node.js $NodeVersion installed"
Step 3: Verify Installation
Open a new PowerShell window to pick up the updated PATH:
node --version
npm --version
node -e "console.log('Node.js is working:', process.version, 'on', process.platform)"
Check the installation paths:
Get-Command node | Select-Object Source
Get-Command npm | Select-Object Source
Step 4: Install nvm-windows for Version Management
For servers that need to run multiple projects with different Node.js version requirements, nvm-windows (Node Version Manager for Windows) allows switching between installed versions easily:
$NvmVersion = "1.1.12"
$NvmInstaller = "nvm-setup.exe"
Invoke-WebRequest -Uri "https://github.com/coreybutler/nvm-windows/releases/download/$NvmVersion/$NvmInstaller" -OutFile "C:Temp$NvmInstaller"
Start-Process -FilePath "C:Temp$NvmInstaller" -ArgumentList "/SILENT" -Wait
Write-Host "nvm-windows installed"
After installation, open a new PowerShell window and use nvm to install and manage Node.js versions:
nvm install 18.20.4
nvm install 20.15.1
nvm use 18.20.4
nvm list
Step 5: Configure npm Global Package Directory
By default, npm installs global packages in the user profile directory, which can cause permission issues when running as a service account. Redirect global packages to a system-level directory:
New-Item -ItemType Directory -Path "C:NodeGlobalmodules" -Force
New-Item -ItemType Directory -Path "C:NodeGlobalcache" -Force
npm config set prefix "C:NodeGlobal"
npm config set cache "C:NodeGlobalcache"
# Add the global bin directory to system PATH
$CurrentPath = [System.Environment]::GetEnvironmentVariable("Path","Machine")
if ($CurrentPath -notlike "*C:NodeGlobal*") {
[System.Environment]::SetEnvironmentVariable("Path","$CurrentPath;C:NodeGlobal","Machine")
}
Write-Host "npm global directory configured: C:NodeGlobal"
Step 6: Install Visual C++ Build Tools
Many npm packages with native addons (bcrypt, sharp, node-sass, etc.) require the Visual C++ compiler toolchain. Install the build tools:
npm install --global --production windows-build-tools
# Or install via Chocolatey:
choco install visualcppbuildtools -y
Alternatively, install the full Visual Studio 2015 Build Tools MSI for WS2012 R2 compatibility. Also install Python 2.7 which is required by node-gyp (the native addon build tool):
choco install python2 -y
npm config set python "C:Python27python.exe"
npm config set msvs_version 2015
Step 7: Configure npm for Corporate Proxy or Private Registry
In enterprise environments, npm traffic may need to go through a proxy, or packages may be served from a private registry (Nexus, Artifactory, Azure Artifacts):
# Configure HTTP proxy
npm config set proxy "http://proxy.yourdomain.com:8080"
npm config set https-proxy "http://proxy.yourdomain.com:8080"
# Configure private registry
npm config set registry "https://nexus.yourdomain.com/repository/npm-group/"
# Configure authentication token for private registry
npm config set "//nexus.yourdomain.com/repository/npm-group/:_authToken" "your-auth-token"
# Verify npm configuration
npm config list
Step 8: Install Common Global Packages
# Install commonly needed global tools
npm install -g pm2 # Process manager for Node.js apps
npm install -g yarn # Alternative package manager
npm install -g http-server # Simple HTTP server for static files
npm install -g typescript # TypeScript compiler
npm install -g rimraf # Cross-platform rm -rf
npm install -g cross-env # Environment variable management for CI
# Verify global packages
npm list -g --depth=0
Step 9: Configure PM2 as a Windows Service
PM2 is the standard Node.js process manager that keeps applications running, restarts them on crash, and manages log files. Configure a Node.js application as a Windows service using PM2:
# Start an application with PM2
pm2 start C:AppsMyNodeAppserver.js --name "my-node-app" --interpreter node
# Save the process list for resurrection after reboot
pm2 save
# Install PM2 as a Windows service (requires pm2-windows-service)
npm install -g pm2-windows-service
pm2-service-install -n PM2
# Start the PM2 service
Start-Service PM2
Get-Service PM2 | Select-Object Name, Status
Step 10: Run a Test Node.js Application
$TestScript = @'
const http = require('http');
const os = require('os');
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify({
server: os.hostname(),
nodeVersion: process.version,
platform: process.platform,
uptime: process.uptime(),
message: 'Node.js on Windows Server 2012 R2'
}));
});
server.listen(3000, () => {
console.log('Test server running at http://localhost:3000');
});
'@
Set-Content -Path "C:Temptest-server.js" -Value $TestScript
node "C:Temptest-server.js" &
Start-Sleep -Seconds 2
Invoke-WebRequest -Uri "http://localhost:3000" -UseBasicParsing | Select-Object -ExpandProperty Content
Summary
Node.js and npm are now installed and configured on Windows Server 2012 R2. The installation includes Node.js 18 LTS via the Windows MSI installer (or optional nvm-windows for multi-version management), a redirected global package directory in a system-accessible location, Visual C++ Build Tools and Python 2.7 for native module compilation, proxy and private registry configuration for enterprise environments, PM2 for managing Node.js applications as Windows services, and a verified test HTTP server. This Node.js installation supports running Express.js APIs, Next.js applications, build toolchains for modern front-end frameworks, and automation utilities as part of the Windows Server DevOps infrastructure.