NodeJS Portable
Since i mostly work with an external SSD with wirtual machine, with installed a portable maven, nuget and npm server, i wanted to have on this ssd nodejs too. Searching on StackOverflow i had no luck, so i defined the following process:
A version with several other servers (Kafka, Rabbit etc...) is available at this address.
Preparation
- Download node.js zip and extract in a directory, let's say "G:\node.8.11.4".
- Add the batch file "run.bat" in the "G:\node.8.11.4" dir. This will setup all the data for this version to run. The default configurations will be overwritten by this batch
@ECHO OFF
IF %MY_NODE_DIR%x == x GOTO SET_PATH
REM GOTO END
:SET_PATH
set MY_NODE_DIR=%~dp0
set NODE=%MY_NODE_DIR%
set NODE_PATH=%MY_NODE_DIR%node_modules
set NPM_GLOBAL_PATH=%MY_NODE_DIR%npm-global
SET PATH=%NODE%;%NPM_GLOBAL_PATH%;%PATH%
mkdir npm-cache
mkdir npm-global
if exist %NODE_PATH%\npm\npmrc.real (
del /q %NODE_PATH%\npm\npmrc
) else (
copy %NODE_PATH%\npm\npmrc %NODE_PATH%\npm\npmrc.real
)
if exist %USERPROFILE%\.npmrc.real (
del /q %USERPROFILE%\.npmrc
) else (
copy %USERPROFILE%\.npmrc %USERPROFILE%\.npmrc.real
)
echo prefix=%NODE%npm-global> %USERPROFILE%\.npmrc
echo cache=%NODE%npm-cache>> %USERPROFILE%\.npmrc
:END
- add the batch file "stop.bat" in the "G:\node.8.11.4" dir, this will restore the settings for the pre-existing node installations
set MY_NODE_DIR=%~dp0
set NODE=%MY_NODE_DIR%
set NODE_PATH=%MY_NODE_DIR%node_modules
set NPM_GLOBAL_PATH=%MY_NODE_DIR%npm-global
if exist %NODE_PATH%\npm\npmrc.real (
del /q %NODE_PATH%\npm\npmrc
copy %NODE_PATH%\npm\npmrc.real %NODE_PATH%\npm\npmrc
)
if exist %USERPROFILE%\.npmrc.real (
del /q %USERPROFILE%\.npmrc
copy %USERPROFILE%\.npmrc.real %USERPROFILE%\.npmrc
)
Usage
Now to start working via command line should start "Start.bat" and then go into any directory whe want to work with, when finished should call the stop.bat to restore any previous condition