Skip to content

Instantly share code, notes, and snippets.

@yrong
Created November 1, 2019 08:24
Show Gist options
  • Save yrong/dbfde39662b706bdf73c820e5ca292e7 to your computer and use it in GitHub Desktop.
Save yrong/dbfde39662b706bdf73c820e5ca292e7 to your computer and use it in GitHub Desktop.
install node&pm2 and make app as service
write-host "check administator rights"
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
write-Warning "This setup needs admin permissions. Please run this file as admin."
exit
}
write-host "check os and powershell"
if (-NOT ([Environment]::Is64BitProcess))
{
write-Warning "windows is not 64 bit"
exit
}
if ([Environment]::Is64BitProcess -ne [Environment]::Is64BitOperatingSystem)
{
write-Warning "PowerShell process does not match the OS"
exit
}
write-host "install .net"
Start-Process -Wait -FilePath dotNetFx40_Full_setup
$node_msi = "node-v12.13.0-x64.msi"
if (Get-Command node -errorAction SilentlyContinue) {
write-host "node already installed,check version requirement"
$node_ver=(Get-Command node | Select-Object -ExpandProperty Version).toString()
if ([System.Version]$node_ver -lt [System.Version]"10.17.0") {
write-Warning "node installed but version too old,please upgrade or reinstall"
exit
}
}else{
write-host "start install $node_msi"
#Start-Process -Wait -FilePath $node_msi
msiexec.exe /n /i $node_msi /quiet
$env:Path += ";C:\Program Files\nodejs\"
$env:Path += ";$Env:USERPROFILE\AppData\Roaming\npm\"
refreshenv
while (-not (Get-Command npm -errorAction SilentlyContinue)) {
Start-Sleep -Seconds 1
}
write-host "node install finished!"
}
write-host "install pm2"
npm install pm2-4.1.2.tgz -g
npm install pm2-windows-startup-1.0.3.tgz -g
write-host "install echo-agent as service"
cd ..
npm run install_as_service
write-host "done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment