-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-nodejs.ps1
More file actions
56 lines (51 loc) · 1.64 KB
/
setup-nodejs.ps1
File metadata and controls
56 lines (51 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# setup-nodejs.ps1
# Smart Node.js PATH setup for current PowerShell session
# Only sets up if Node.js is not already accessible
# Check if Node.js is already available
$nodeAvailable = $false
try {
$null = Get-Command node -ErrorAction Stop
$nodeAvailable = $true
} catch {
$nodeAvailable = $false
}
if ($nodeAvailable) {
Write-Host "✅ Node.js is already available in this session" -ForegroundColor Green
Write-Host "Node.js version: " -NoNewline -ForegroundColor Yellow
node --version
Write-Host "npm version: " -NoNewline -ForegroundColor Yellow
npm --version
} else {
Write-Host "🔧 Setting up Node.js for current session..." -ForegroundColor Cyan
# Add Node.js to PATH for current session
$env:PATH += ";C:\Program Files\nodejs"
# Verify installation
try {
Write-Host "Node.js version: " -NoNewline -ForegroundColor Yellow
node --version
Write-Host "npm version: " -NoNewline -ForegroundColor Yellow
npm --version
Write-Host "✅ Node.js is now ready for this session!" -ForegroundColor Green
} catch {
Write-Host "❌ Failed to setup Node.js. Check installation path." -ForegroundColor Red
exit 1
}
}
# Export a function to check Node.js status
function Test-NodeJSSetup {
try {
$nodeVersion = node --version
$npmVersion = npm --version
return @{
Available = $true
NodeVersion = $nodeVersion
NpmVersion = $npmVersion
}
} catch {
return @{
Available = $false
NodeVersion = $null
NpmVersion = $null
}
}
}