Skip to main content

PowerShell 使用技巧(管理员运行)

# 创建配置文件
New-Item -Path $PROFILE -ItemType File -Force
# 编辑配置文件
notepad $PROFILE
# 允许运行脚本
Set-ExecutionPolicy RemoteSigned

一、win 使用 FNM 自动切换 Node.js 版本

初始化 FNM 并启用进入目录时自动切换 Node.js 版本

# 缓存 fnm 是否存在
$useFnm = $null -ne (Get-Command fnm -ErrorAction SilentlyContinue)

# 优先检测 .node-version,再 .nvmrc
$versionFile = $null
if (Test-Path ".node-version") {
$versionFile = ".node-version"
} elseif (Test-Path ".nvmrc") {
$versionFile = ".nvmrc"
}

# 如果找到版本文件
if ($versionFile) {
$version = (Get-Content $versionFile -Raw).Trim()
if ($version) {
if ($useFnm) {
fnm use $version
} else {
nvm use $version
}
}
}

# 代理
$env:HTTP_PROXY = "http://127.0.0.1:7897"
$env:HTTPS_PROXY = "http://127.0.0.1:7897"
$env:ALL_PROXY = "socks5://127.0.0.1:7897"
# 不走代理的地址
$env:NO_PROXY = "localhost,127.0.0.1,::1,.local,10.0.0.0/8,192.168.0.0/16,172.16.0.0/12,gitee.com"

目录下新建 .node-version 文件,内容:20.18.3

二、win 内网映射

8000代表映射的本地端口,如果不可用,请尝试80或查看防火墙

ssh -R 80:localhost:8000 serveo.net