首先需要搞清楚node在本地是怎么安装配置、然后在根据如下步骤编写bat脚本:
思路
1.下载需要安装node版本zip格式包
2.配置环境变量
3.安装插件
可以根据自己需要来定义与配置(如下添加redis与node配置)
bat脚本:
@echo off
echo windows10 x64 env-path-node-set
REM 请求管理员权限并隐藏窗口
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 :: & echo 执行中,请稍候... & timeout 2 > nul","","runas",0)(window.close)&&exit
setlocal enabledelayedexpansion
REM 设置 node、redis 目录变量,方便后续引用和修改
%~d0
cd %~dp0
set "CURRENT_DIR=%~dp0"
set "CURRENT_DIR=%CURRENT_DIR:~0,-1%"
set "NODE_INSTALL_DIR=%CURRENT_DIR%\node-v16.14.2"
set "NODE_GLOBAL_DIR=%CURRENT_DIR%\node-v16.14.2\node_global"
set "REDIS_INSTALL_DIR=%CURRENT_DIR%\Redis-5.0.14.1"
REM 检查环境变量中是否已存在 Node.js 路径
echo windows10 x64 node config is exist???
for /f "tokens=1,* delims==" %%a in ('set PATH') do (
if /i "%%b"=="%NODE_INSTALL_DIR%" (
echo env-path is exist, over ...
goto :eof
)
)
rem 设置path环境变量
echo windows10 x64 env-path update
setx /M PATH "%PATH%;%NODE_INSTALL_DIR%;%NODE_GLOBAL_DIR%;%REDIS_INSTALL_DIR%"
echo env-path-node-set success
REM 执行完成后自动关闭
timeout /t 1 >nul
exit
亲测有效。