NodeJS | Setup environments

Working with multiple NodeJS Versions

If you plan to work with different NodeJS Version, we suggest to setup the following folder structure. Choose for #YOUR ROOT# whatever you want as your base folder, e.g. D:\Development

Install NodeJs Binary Package (.zip File)

Download and extract the NodeJS Binary Package to your destination folder:

Version32 Bit64 Bit
14.15.1https://nodejs.org/dist/v14.15.1/node-v14.15.1-win-x86.ziphttps://nodejs.org/dist/v14.15.1/node-v14.15.1-win-x64.zip
15.2.1https://nodejs.org/dist/v15.2.1/node-v15.2.1-win-x86.ziphttps://nodejs.org/dist/v15.2.1/node-v15.2.1-win-x64.zip

So, NodeJS 15.2.1 Files should be extracted to:

 #YOUR ROOT#\Environments\NodeJS\15.2.1\node

Kepp in mind: if you extract the zip file. it creates a folder with the name of the zipfile and extracts all files in this folder, e.g. node-v15.2.1-win-x86.

We wil call this installation folder HOME_NODE.

HOME_NODE = "D:\Development\Environments\NodeJS\15.2.1"

So, best practice is to extract the zip file in the NodeJS folder #YOUR ROOT#\Environments\NodeJS\15.2.1 ($HOME_NODE) and rename node-v15.2.1-win-x86 to node after extraction is complete.

Your finale folder structure should look like this:

Create start script

Create a start script to setup up environment variables and path:

Powershell

#
#
#
$NODE_VERSION              = "15.2.1"
$ENV:NODE_HOME             = "D:\Development\Environments\NodeJS\$NODE_VERSION"
$ENV:NPM_CONFIG_USERCONFIG = "$ENV:NODE_HOME\.npmrc"

$ENV:NPM_CONFIG_REGISTRY   = "http://localhost:4873"
$ENV:NPM_CONFIG_PREFIX     = "$ENV:NODE_HOME\npm"

$ENV:PATH="$ENV:NODE_HOME\node;$ENV:NODE_HOME\npm;$ENV:PATH;"

Write-Host "╔══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗"
Write-Host "║                                       N O D E J S  ---  P L A Y G R O U N D                                          ║"
Write-Host "╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝"

npm config set registry "$ENV:NPM_CONFIG_REGISTRY"

echo "HOME_NODE           = $ENV:NODE_HOME"
echo "NODE                = $((Get-Command node.exe).Path)"
echo "NPM_CONFIG_PREFIX   = $ENV:NPM_CONFIG_PREFIX"
echo "NPM_CONFIG_REGISTRY = $ENV:NPM_CONFIG_REGISTRY"

Create a Shortcut

Create a Shortcut for this file by dragging the powershell script (with pressed ALT key).

Rename the Shortcut, e.g. “Start NodeJS 15.2.1”

Edit the Shortcut properties

Right-Mouse-Click on Symbol and then select Properties:

Change Destination to:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit D:\Development\Environments\NodeJS\15.2.1\set_env.ps1

Explanation

Call the powershell program

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

With the parameter

 -noexit

And the parameter

D:\Development\Environments\NodeJS\15.2.1\set_env.ps1

Which means:

Call Poweshell to run the script set_env.ps1 and stay in Powershell after the Script is finished.

Configure with .npmrc

Create a configuraton file .npmrc in the folder $HOME_NODE (e.g. D:\Development\Environments\NodeJS\15.2.1) using your favourite editor.

notepad D:\Development\Environments\NodeJS\15.2.1\.npmrc

Add this line to the file:

cache=D:\Development\Environments\NodeJS\15.2.1\npm-cache

Save the file

Run the script

Double-Click on the shortcut

Leave a comment

Your email address will not be published. Required fields are marked *