Last active
March 20, 2023 08:53
-
-
Save manuelbieh/3864088 to your computer and use it in GitHub Desktop.
Install node.js + some packages on Windows via Batchfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
NET SESSION >nul 2>&1 | |
IF %ERRORLEVEL% NEQ 0 ( | |
echo This setup needs admin permissions. Please run this file as admin. | |
pause | |
exit | |
) | |
set NODE_VER=null | |
set NODE_EXEC=node-v0.8.11-x86.msi | |
set SETUP_DIR=%CD% | |
node -v >tmp.txt | |
set /p NODE_VER=<tmp.txt | |
del tmp.txt | |
IF %NODE_VER% NEQ null ( | |
echo INSTALLING node ... | |
mkdir tmp | |
IF NOT EXIST tmp/%NODE_EXEC% ( | |
echo Node setup file does not exist. Downloading ... | |
cd ../bin | |
START /WAIT wget http://nodejs.org/dist/v0.8.11/%NODE_EXEC% | |
move %NODE_EXEC% %SETUP_DIR%/tmp | |
) | |
cd %SETUP_DIR%/tmp | |
START /WAIT %NODE_EXEC% | |
cd %SETUP_DIR% | |
) ELSE ( | |
echo Node is already installed. Proceeding ... | |
) | |
cd ../.. | |
echo INSTALLING grunt ... | |
call npm install -g grunt-cli | |
REM echo INSTALLING grunt-less grunt-copy grunt-clean grunt-compress ... | |
REM call npm install grunt-contrib-less grunt-contrib-copy grunt-contrib-clean grunt-contrib-compress | |
cd %SETUP_DIR% | |
echo DONE! |
Thanks men, I wrote a similar code but my error is not calling "call" :D
Excuse me guys, why is line 16 this: "IF %NODE_VER% NEQ null ("
Shouldn't it be "IF %NODE_VER% EQ null ("?
This doesn't work for me. I get 'Windows cannot find wget'
You will need to install GnuWin for this script to work. See http://gnuwin32.sourceforge.net/packages/wget.htm
Not worked for me, Getting "Windows cannot find wget" error on execution
If you don't want to or can't use wget like me, use this:
set NULL_VAL=null
set NODE_VER=%NULL_VAL%
set NODE_EXEC=node-v10.15.3-x86.msi
node -v >.tmp_nodever
set /p NODE_VER=<.tmp_nodever
del .tmp_nodever
IF "%NODE_VER%"=="%NULL_VAL%" (
echo.
echo Node.js is not installed! Please press a key to download and install it from the website that will open.
PAUSE
start "" http://nodejs.org/dist/v10.15.3/%NODE_EXEC%
echo.
echo.
echo After you have installed Node.js, press a key to shut down this process. Please restart it again afterwards.
PAUSE
EXIT
) ELSE (
echo A version of Node.js ^(%NODE_VER%^) is installed. Proceeding...
)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just stumbled across your script because I want to write a similar script.
Shouldn't line 16 be
IF %NODE_VER% == null
instead ofNEQ null
?If node is not installed,
set /p NODE_VER=<tmp.txt
will not changeNODE_VER
and it will stay null.