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

@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

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


Last modified on: December 17, 2019