Skill body
environment-setup-node
Goal
Prepares a stable Node.js and npm environment by validating the active Node runtime, confirming npm availability, and checking basic npm connectivity and health diagnostics.
Decision Logic
- If
nodeis missing or major version is< 20: install/upgrade Node.js to active LTS. - If a maintained Node version manager exists (
nvm,fnm,asdf): use it as the primary way to install/switch Node versions. - If no Node version manager is available on Windows: install
fnmwithwingetand continue non-interactively. - If Windows shell cannot find
nodeafterfnmsetup: configure PowerShell profile to initializefnm, then open a new terminal (or reload profile). - If
npmis unavailable: repair npm environment before continuing. - If
npm pingfails: resolve registry/network configuration before continuing.
Instructions
- Detect Node version management tools
command -v nvm || true command -v fnm || true command -v asdf || trueWindows PowerShell:
Get-Command fnm -ErrorAction SilentlyContinue Get-Command nvm -ErrorAction SilentlyContinue Get-Command winget -ErrorAction SilentlyContinuePrefer this order when available:
fnm/nvm/asdf. If none is available on Windows, installfnmnon-interactively and continue:winget install Schniz.fnm --accept-source-agreements --accept-package-agreementsThen initialize
fnmin the current shell:$fnmDir = "$env:LOCALAPPDATA\Microsoft\WinGet\Packages\Schniz.fnm_Microsoft.Winget.Source_8wekyb3d8bbwe" if (Test-Path $fnmDir) { $env:PATH = "$fnmDir;$env:PATH" } fnm env --shell powershell | Invoke-Expression fnm install --lts fnm use lts-latest fnm default lts-latestPersist for all new Windows PowerShell sessions (beginner-friendly):
$profileDir = Split-Path -Parent $PROFILE if (-not (Test-Path $profileDir)) { New-Item -ItemType Directory -Force $profileDir | Out-Null } if (-not (Test-Path $PROFILE)) { New-Item -ItemType File -Force $PROFILE | Out-Null } $fnmDir = "$env:LOCALAPPDATA\Microsoft\WinGet\Packages\Schniz.fnm_Microsoft.Winget.Source_8wekyb3d8bbwe" Add-Content $PROFILE "`n# fnm bootstrap" Add-Content $PROFILE ('$env:PATH = "{0};$env:PATH"' -f $fnmDir) Add-Content $PROFILE 'fnm env --shell powershell | Invoke-Expression'Profile location example on Windows PowerShell:
$PROFILEIf
npmis blocked with a script policy error (npm.ps1 cannot be loaded), set per-user execution policy:Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -ForceThen open a new terminal tab, or reload profile in current terminal:
. $PROFILE - Verify Node and npm availability
node -v npm -vWindows PowerShell:
node -v npm -v - Validate npm connectivity
npm pingWindows PowerShell:
npm pingEnsure connectivity succeeds before continuing.
- Validate active Node runtime details
node -p 'process.versions.node'Windows PowerShell:
node -p "process.versions.node"Confirm the runtime is an active LTS release; if not, switch Node version using the detected version manager.
- Windows troubleshooting quick checks (when
nodeis still not found)$PROFILE Test-Path $PROFILE Get-Content $PROFILE Get-Command fnm -ErrorAction SilentlyContinue Get-Command node -ErrorAction SilentlyContinueIf
Get-Command nodeis empty, run:. $PROFILE fnm use lts-latest node -v npm -v - Agent completion criteria
Mark complete only when all are true:
node -vandnpm -vsucceed- npm registry connectivity check succeeds (
npm ping) - active Node runtime is an LTS release
Constraints
- Prefer Node.js LTS versions only.
- Prefer maintained version-managed Node installations (
fnm,nvm,asdf) when available. - Avoid using
sudoin setup commands; prefer user-space tooling when permissions are restricted. - Use deterministic terminal checks, not assumptions.