Skip to content

Instantly share code, notes, and snippets.

@manuelbieh
Last active March 20, 2023 08:53
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save manuelbieh/3864088 to your computer and use it in GitHub Desktop.
Save manuelbieh/3864088 to your computer and use it in GitHub Desktop.
Install node.js + some packages on Windows via Batchfile
@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!
@ozomer
Copy link

ozomer commented Jul 5, 2015

I just stumbled across your script because I want to write a similar script.
Shouldn't line 16 be IF %NODE_VER% == null instead of NEQ null?
If node is not installed, set /p NODE_VER=<tmp.txt will not change NODE_VER and it will stay null.

@thEpisode
Copy link

Thanks men, I wrote a similar code but my error is not calling "call" :D

@jon-w1
Copy link

jon-w1 commented Sep 12, 2016

Excuse me guys, why is line 16 this: "IF %NODE_VER% NEQ null ("

Shouldn't it be "IF %NODE_VER% EQ null ("?

@miparnisari
Copy link

This doesn't work for me. I get 'Windows cannot find wget'

@impressto
Copy link

You will need to install GnuWin for this script to work. See http://gnuwin32.sourceforge.net/packages/wget.htm

@arvind-india
Copy link

Not worked for me, Getting "Windows cannot find wget" error on execution

@Sv443
Copy link

Sv443 commented Apr 17, 2019

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