Install Windows Terminal
If you are using Windows 11, good news: you already have the Windows Terminal installed. If not, open the Microsoft Store and download it free of charge.
This is a hardware-accelerated tabbed terminal from which you can run Powershell, CMD or WSL interfaces, and a touchstone (and, some would say, pretty belated) step to approach Windows development experience to other major OS's. Installing this terminal is highly recommended if you plan to develop on Windows, using node.js or else.
Install NVM for Windows
Now, instead of installing node.js from the official website, we should install the Node Version Manager and download node versions from there. In case you already have node installed this should not be a major problem as NVM will overwrite any node-related environment variables and symlinks, but I'd recommend you to uninstall it anyway as this process will render the current installation completely useless.
Go to the NVM for windows project page and download the latest available version's
nvm-setup.zip from the releases page.
Note that this is not the same as the UNIX-based NVM project, although it is functionally equivalent. "Similar, not identical" as the project itself discloses.
Unzip the folder's contents and run
However, you'll then be prompted to indicate where to keep the node.js symlink, and (at least in versions up to 1.1.8) there's a catch: you cannot keep the symlink under a path which contains whitespaces, and unfortunately the default installation path (currently
C:\Program Files\nodejs) steps right into this trap.
This is where I've installed my local NVM. It's only a suggestion and you can install wherever you like (as long as the path does not contain whitespace), I'd only recommend the target folder's name to be something like
\nodejs so you don't end up losing the installation, which can be removed directly from the standard uninstaller anyway.
Install Node & Setup NVM
First of all, you need to run Windows Terminal with administrative privileges. One way this can be done is by looking for the terminal in the system's internal search, clicking with the right button on its icon and then selecting 'Run as Administrator'.
Any time you feel lost while fiddling with NVM, simply type
nvm in the terminal and a very concise manual will pop up explaining each available command and their parameters.
Let's make sure NVM is enabled, run:
And after that, let's install the current Long Term Support version, pre-aliased as
lts (currently 14.18.1):
nvm install lts
After the installation finish, we must declare to NVM what version we'd like to use:
nvm use 14.18.1
Great! Now, node.js-specific commands such as
npm will be mapped to that node version. Let's celebrate by installing the yarn package manager:
npm install -g yarn
After the installation ends, let's check if everything went OK:
If you get the yarn version as output, congratulations! The set-up was properly done.
Managing Multiple NodeJS Versions
Now that we have the LTS version, what's the good of having a version manager if not to use different versions? Let's also install the most recent node version, pre-aliased as
latest (currently 16.11.1):
nvm install latest
Anytime you'd like to check your locally installed versions, run
to get a list of the ones available in your system. To change your current version, simply run nvm use again, this time pointing to the newly-installed one:
nvm use 16.11.1
Note that if you run
yarn -v again you will not receive a version number as yarn is not currently installed for your local 16.11.1; every installed version is completely self-contained, which includes access to global packages.
Congratulations, you are now an organized Windows NodeJS developer who follows the best practices of localized version management.
Troubleshooting Common Problems
My downloads through npm/yarn are REALLY slow.
First of all, make sure the network you are connected to is classified as 'private' by windows, as the windows firewall can be very picky on public networks. In case the problem persists, whitelist the nvm directory (should be
C:\Users\<your_user_name>\AppData\Roaming\nvm if you kept the defaults) in your antivirus software.
Running stuff in node (e.g. transpiling a Typescript project) is REALLY slow.
Windows uses the NTFS filesystem which is particularly bad at dealing with tasks involving a very big number of small files and Node JS projects are notorious for the many different modules which depend on many different other modules, so this problem is harder to mitigate. Short of getting an SSD, your best bet would be to set up node.js on Windows Subsystem for Linux in case execution speed is unworkably slow.
I'm getting a 145 exit code in some NVM commands.
Take a look at the Install NVM for Windows part of this tutorial, especially the one regarding the symlink location. You must have installed NVM in a directory path with whitespaces; uninstall NVM and re-run
nvm-setup.exe, this time making sure no selected paths contain whitespaces.
Top comments (0)