Node.js

Source: [REF-1] Install Node.js Locally with Node Version Manager (nvm)

On the Windows host, best to setup WSL and install node.js in the WSL. Also put the code folder and all the nodejs modules in WSL. Then, run VS Code from the Windows host and connect remotely to the code folder on WSL. [also see this article]

See Windows WSL for setup and Connect VS Code to WSL folder.

Install - FRESH nodejs using fnm, or nvm

fnm (Fast Node Manager) is the latest and recommended package manager now.

Updated: 2024 Jul

source: https://nodejs.org/en/download/package-manager/

# installs fnm (Fast Node Manager)
curl -fsSL https://fnm.vercel.app/install | bash
# download and install Node.js
fnm use --install-if-missing 20
# verifies the right Node.js version is in the environment
node -v # should print `v20.15.1`
# verifies the right NPM version is in the environment
npm -v # should print `10.7.0`

[Alternative] Install - nodejs using apt

Installing Node.js with Apt from the Default Repositories

[REF-4]

sudo apt update
sudo apt install nodejs
node -v
sudo apt install npm
Installing Node.js with Apt Using a NodeSource PPA

[REF-4] PPA (personal package archive) maintained by NodeSource. These PPAs have more versions of Node.js available than the official Ubuntu repositories. Node.js v12, v14, and v16 are available as of the time of writing.

cd ~
curl -sL https://deb.nodesource.com/setup_16.x -o /tmp/nodesource_setup.sh
# CHECK the content of the setup script
#nano /tmp/nodesource_setup.sh
sudo bash /tmp/nodesource_setup.sh
sudo apt install nodejs
node -v
npm -v

Update nodejs version in WSL

Source: Install Node.js on Windows Subsystem for Linux (WSL2)

  • Tested (Jul 2024) on the following existing setup: nvm, nodejs have been installed but older version then need to update; Current LTS version: v20.15.1;

  • Inspect existing environments:

wsl:~$ node --version
v18.16.0
wsl:~$ npm --version
9.5.1
wsl:~$ nvm --version
0.39.3
wsl:~$ nvm ls
->     v18.16.0
default -> lts/* (-> v18.16.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v18.16.0) (default)
stable -> 18.16 (-> v18.16.0) (default)
lts/* -> lts/hydrogen (-> v18.16.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.0 (-> N/A)
lts/hydrogen -> v18.16.0
  • Update nodejs

# find the available versions
nvm ls-remote
nvm install 20.15.1
nvm install 20.15.1 --reinstall-packages-from=18.16.0
# upgrade npm if necessary
npm install -g npm@10.8.1
# uninstall old version
nvm uninstall 18.16.0

References

Last updated