Node JS | 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.
All NodeJS Archives are here:
https://nodejs.org/dist/v${dist_version}/node-v${dist_version}-win-x64.zip"
So, NodeJS 18.0.0 Files should be extracted to:
#YOUR ROOT#\Environments\NodeJS\18.0.0\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-v18.0.0-win-x86
.
We will call this installation folder HOME_NODE
.
HOME_NODE = "D:\Development\Environments\NodeJS\18.0.0"
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 set_env.ps1
to setup up environment variables and path:
Powershell
$NODE_VERSION = "18.0.0" $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:OPENSSL_CONF = '' $ENV:PATH="$ENV:NODE_HOME\node;$ENV:NODE_HOME\npm;$ENV:NODE_HOME\node_modules\npm\bin;$ENV:PATH" Write-Host "╔═══════════════════════════════════════════════════════════════════════════════════════════════════════╗" Write-Host "║ Node JS ║" 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"
Depending on your security settings, you must sign the script.
Read here on how to do this.
Fix for Version 18.x.x
Using the original archive, you may get an error when you run node.exe
To fix this, set the environment variable OPENSSL_CONF (as we already did in set_env.ps1)
$ENV:OPENSSL_CONF = ''
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 18.0.0”
Edit the Shortcut properties
Right-Mouse-Click on Symbol and then select Properties:
Change Destination to:
powershell.exe -noexit D:\Development\Environments\NodeJS\18.0.0\set_env.ps1
Explanation
Call the PowerShell program
powershell.exe
With the parameter
-noexit
And the parameter
D:\Development\Environments\NodeJS\18.0.0\set_env.ps1
Which means:
Call PowerShell to run the script set_env.ps1
and stay in PowerShell after the Script is finished.
Configure with .npmrc
Create a configuration file .npmrc in the folder $HOME_NODE (e.g., D:\Development\Environments\NodeJS\18.0.0
) using your favourite editor.
notepad D:\Development\Environments\NodeJS\18.0.0\.npmrc
Add this line to the file:
cache=D:\Development\Environments\NodeJS\15.2.1\npm\cache cache-folder=D:\Development\Environments\NodeJS\15.2.1\yarn\cache global-folder=D:\Development\Environments\NodeJS\15.2.1\yarn prefix=D:\Development\Environments\NodeJS\15.2.1\npm
Save the file
Run the script
Double-Click on the shortcut
Tipps und Tricks
Install Build Tools
Some packages need to build from source. These packages require additional tool, e.g. compiler.
Install all the required tools and configurations using Microsoft’s windows-build-tools using npm install --global --production windows-build-tools
from an elevated PowerShell or CMD.exe (run as Administrator).
npm install --global --production windows-build-tools