-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_server.ps1
More file actions
34 lines (27 loc) · 1.16 KB
/
Copy pathstart_server.ps1
File metadata and controls
34 lines (27 loc) · 1.16 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
$ErrorActionPreference = "Stop"
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
$serverDir = Join-Path $root "server"
$port = if ($env:PORT) { $env:PORT } else { "3000" }
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Smart Vocab Server" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
foreach ($p in @($port)) {
$procIds = netstat -ano | Select-String ":$p\s" | ForEach-Object {
($_ -split '\s+')[-1]
} | Where-Object { $_ -match '^\d+$' -and $_ -ne '0' } | Sort-Object -Unique
foreach ($procId in $procIds) {
Stop-Process -Id ([int]$procId) -Force -ErrorAction SilentlyContinue
Write-Host "Stopped process on port $p (PID $procId)" -ForegroundColor DarkGray
}
}
Set-Location $serverDir
if (-not (Test-Path "node_modules")) {
Write-Host "Installing server dependencies..." -ForegroundColor Yellow
npm install
}
Write-Host "Starting API server at http://localhost:$port" -ForegroundColor Green
npm start