Windows 10 has a feature that allows you to run Linux in a lightweight virtual container.
WSL allows easy access to and from Windows/Linux filing systems.
It runs a special version of the Linux kernel to achieve tight integration with Windows. You may install a number of different Linux distributions from the Windows Store, Ubuntu being the original and probably best developed. You cannot (yet) easily run a Linux desktop but this should be integrated in 2021H2. In addition, WSL does not use systemd as most distributions now do.
How to install Node.js and Node-RED
-
Install node.js from the official installation page. If you are using a Debian-based distribution on WSL, I strongly recommend using the NodeSource binary distributions.
-
Install Node-RED using
npm -g install node-redor my alternate-node-red-installer. -
Start node-red
-
Panic because you now don't know how to access the started web server!
It is OK, no need for panic. Microsoft have crafted some magic so that localhost (AKA 127.0.0.1) on WSL is mapped over to the same on the Windows host.
But now something really weird happens. You can start Node-RED on the host and in WSL - with the same PORT! When you do, the WSL version takes preference.
Incidentally, because WSL is a virtual environment, it has its own virtual network interface (It actually uses Hyper-V) with its own IP address, something in the range 172.20.*.*. Unfortunately, this may not be the same address every time WSL is started.
I add the following to my ~/.bashrc script in WSL so that I can see the IP address every time I start it:
export WSL_IP=`ip route get 1 | awk '{gsub("^.*src ",""); print $1; exit}'`
echo "WSL Local IP Address: $WSL_IP"
This has an impact if you want to make your WSL-based service available from outside the host (e.g. from a different device). In that case, you will need to look up the various work-arounds that have been published that grab the IP address and create firewall forwarding rules.
PS: If you are going to the trouble of using WSL on Windows, you will almost certainly want a couple of other things as well:
-
Microsoft Terminal - this is the new windows terminal and beats the pants of the one that comes with Windows. Install via the Windows Store.
-
VSCode - This free IDE/Code Editor is open source but backed by Microsoft. Microsoft have produced a number of extensions including some remote editing extensions for WSL, Docker and SSH.