⚡ PowerShell 5.1+

Get The npm cache Size Report

Reports how much disk space the npm cache is currently using, read-only (no deletion).

By WindowsScripting.com · 805 B
Get-NpmCacheSizeReport.ps1
<#
.SYNOPSIS
    Reports how much disk space the npm cache is using.

.DESCRIPTION
    Recursively sums the size of every file under the npm cache and prints
    a human-readable total, without deleting anything.

.EXAMPLE
    .\Get-NpmCacheSizeReport.ps1
#>

[CmdletBinding()]
param()

$targetPath = "$env:APPDATA\npm-cache"

if (-not (Test-Path $targetPath)) {
    Write-Host "$targetPath does not exist on this machine." -ForegroundColor Yellow
    return
}

$files = Get-ChildItem -Path $targetPath -Recurse -File -Force -ErrorAction SilentlyContinue
$totalBytes = ($files | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum

Write-Host "$targetPath" -ForegroundColor Cyan
Write-Host "  Files: $($files.Count)"
Write-Host "  Total size: $([math]::Round($totalBytes / 1MB, 2)) MB"