In this beginner's tutorial, we'll learn how to install Node.js and npm on Windows, their brief introduction and benefits, and why we may need them in our development environment.
Furthermore, we'll also learn about NVM, which allows us to manage different Node versions.
Let's get started.
What Is Node.js® (nodejs)?
Node.js (also known as nodejs or simply Node) is a cross-platform JavaScript runtime environment that allows the usage and execution of JavaScript outside a web browser. It runs on Google's V8 JavaScript engine, an Open-Source JS engine.
It can be used for creating many applications and other stuff. For example, one of the popular Static Site Generators, Eleventy (or 11ty), is based on and uses Node.js.
Node.js Benefits
While you may think that Node might be related to just application or web development, it's not necessarily the case. You can use it for many other purposes.
For instance, you could create a Node.js application to automate the task of processing images to optimize and minify them using a JavaScript-based tool like Gulp.
Often, it's used to create Node.js servers to serve websites (either locally or online).
Different Node.js Versions or Phases
It's important to understand the different Node.js versions or phases and which one you should use.
There are two versions: the LTS (Long Term Support - stable release) and the Current version (with the latest features in development).
Another phase, the Maintenance phase, contains critical bug fixes and security updates.
Long Term Support (LTS) Version
The LTS version contains many new features and bug fixes. It is stable and recommended for most users.
The latest LTS version is 16.17.1
, which includes npm version 8.15.0
(as of writing this article).
Current Version
The Current version contains most of the latest features, some of which might be under development, useful for developers looking to experience cutting-edge technologies. Thus, it's not advised for beginners and new users to use it when getting started with it.
The latest Current version is 18.10.0
, which includes npm version 8.19.2
(as of writing this article).
You may read about different phases in detail on the Node.js GitHub repository.
Node.js Frameworks
There are many Node.js frameworks available should you prefer to use one. Some popular ones are Express.js, Next.js, and Meteor (MeteorJS).
These frameworks allow you to speed up the coding process by taking care of the many low-level programming challenges and/or repetitive work.
What Is npm?
npm stands for Node Package Manager. As you may have imagined, it is a tool that allows us to easily manage Node.js packages.
npm Benefits
Apart from managing Node.js packages, npm helps us identify which packages have vulnerabilities or issues and automatically offers to fix the possible ones without us having to do the manual work.
What Is NVM?
NVM stands for Node Version Manager, which allows us to manage different Node.js versions. This tool is particularly helpful if you want to run multiple versions of Node.
It has several versions available depending on the Operating System and platform; however, we'll be using Corey Butler's version for Windows. So, if you're on Mac/Linux, you may want to use a different version.
NVM Benefits
With this tool, you can easily switch between multiple versions of Node.js. Unless you have a specific reason to use multiple versions, you would usually stick with a single version.
Getting Started
Unless you're installing Node.js for the first time, you should ensure that it's not already installed on your PC. Otherwise, the installation will overwrite it.
If it's already installed on your PC, consider uninstalling it first. The steps to uninstall Node.js are mentioned below.
Note
It's important to note that when you use and run the terminal, whether you're using Windows Command Prompt, Windows PowerShell, or an integrated terminal of an IDE like VS Code, you should always run as administrator to prevent any admin privileges issues in the future.
This is because these tools try to access some privileged actions and locations on the system.
Checking the Currently Installed Node.js Versions Using Node Version Manager
If you're using NVM, you can check if you already have Node.js installed on your PC or not by using the following command.
nvm list
The terminal should output the list of Node.js installations and their versions if it finds any on your PC.
Uninstall Existing Node.js
Depending on how you installed Node previously, the method to uninstall it varies on the installation type. Below, I've shown two general methods to uninstall it.
Uninstall via the Version Manager
Follow these steps if you're using a version manager.
Launch the terminal and type the following.
nvm uninstall 16.15.1
Here, I'm uninstalling the 16.15.1
version from my PC.
To confirm that Node.js was uninstalled successfully, type the following.
nvm list
As you can see above in the screenshot, it says that "No installations recognized.", which means that there are currently no Node.js installations found on your PC.
Uninstall via the Windows Apps & features Settings
Follow these steps to uninstall Node.js using the Windows Apps & features settings.
Note
Depending on your Windows version, this process might differ slightly, but the general concept is the same.
I've mentioned Windows 11 steps below. Consider searching on the internet for your specific Windows version if you're using Windows 10 or older versions.
Search for and open Apps & features via the Start menu (Windows
key) or from the Settings app (Windows + I
keyboard shortcut) > Apps > Apps & features.
Find Node.js in the apps list and uninstall it.
Node.js Installation
There are two ways to get Node.js; one is using a version manager (recommended), and the other is directly from its website. I'll show you both ways.
Let's see how to download it with a version manager first.
Install Node.js on Windows with Node Version Manager (Recommended)
Step 1 - Download NVM
Go to Corey Butler's GitHub repository and look for the Releases section on the right sidebar. You should see a version (1.1.9
as of writing this article) listed there.
Either click on the Releases or the version link. This should take you to the Releases page, where you can download the tool.
Scroll down until you see the Assets heading, which should have several different files listed for download. The one we'll use in our tutorial is the nvm-setup.exe
file, so go ahead and download it.
Step 2 - Install NVM
Once downloaded, run the installer and follow the setup instructions to complete its installation.
You'll be asked to agree with the license agreement to proceed.
After agreeing to the license, you'll be asked to decide where you want to install it. The default location is fine, so there is no need to change it.
On the next screen, you'll be asked to choose the Node.js Symlink location. Again, you may install it in the default provided location.
Once everything is ready to install, you'll be shown the last confirmation screen. Click the Install button to continue.
Once the installation is finished, you'll be shown a success screen, ensuring the setup was finished successfully.
Step 3 - Confirm the NVM Installation
To ensure it was installed on your system, run the following command in the terminal.
nvm version
It should output a version (1.1.9
as of writing this article) to confirm the installation.
Step 4 - Download Node.js
Type the following in the terminal to begin downloading Node.
nvm install lts
Step 5 - Confirm the Node.js Installation
To confirm the installation, type the following.
node -v
The installation was successful if the terminal outputs a version (v16.17.1
as of writing this article).
Step 6 - Use a Node.js Version
To use the currently downloaded version 16.17.1
, type the following command in the terminal.
nvm use 16.17.1
This command is also used to switch between different Node.js versions.
Install Node.js on Windows with Its Installer
To install it using the installer, follow the steps mentioned below.
Step 1 - Download the Node.js Installer
To install the latest version, go to the official Node.js website and click on the 16.17.1 LTS button (as of writing this article) to download the installer.
You can also install the Current version by simply clicking its download button.
This will begin downloading the stable LTS.
Step 2 - Install Node.js
Once it successfully downloads, run the Node.js installer and follow the setup instructions to complete its installation.
You'll be asked to agree with the license agreement to proceed.
After accepting the license agreement, you'll be shown a screen to decide which custom features of Node.js you want to install. You may leave the settings as default and click the Next button.
On the next screen, you can choose if you want to install optional tools to compile native modules from C/C++ that require the installation of Python and Visual Studio Build Tools. Because some npm modules rely on these tools, you should only check this option if you plan to use those modules in the future.
If you choose to install these optional tools, Chocolatey will also be installed as part of them.
Generally, you don't need these optional tools, so you may safely choose not to install them. In any case, you can always install them later manually or using the installer.
After deciding on all these settings, you'll be shown a confirmation screen to proceed with the installation. Click Install to continue.
You'll be able to track the installation progress to ensure everything is going as expected.
Once installed, a final confirmation screen will be shown to ensure that Node.js is installed.
Step 3 - Confirm the Node.js Installation
To ensure it is successfully installed on your PC, run the below command in the command line.
node -v
If the output returns a version number (v16.17.1
as of writing this article), then that confirms the successful installation of Node.js on your system.
The version of the Node.js installed can also be found by using the same command.
Install npm on Windows
Even though npm comes pre-installed with the newer Node.js versions, you can always get it separately.
To get npm separately, type the following in the terminal.
npm install -g npm
The installation can be confirmed by opening the Command Prompt and typing the following command.
npm -v
If the terminal outputs a version (8.15.0
as of writing this article), then npm was installed successfully.
Conclusion
That's all. You have now successfully installed both, Node.js and npm. Now you can start developing your Node.js applications, web servers, or whatever it is that you need it for.
I hope this tutorial has been helpful to you and cleared any confusion you might have regarding the installation and setup.
Have you used Node before? Or, for what purposes do you plan to use it? Let me know your thoughts by sending me an email at [email protected].
Frequently Asked Questions
Can Node.js Be Installed on Windows?
Yes. Node.js can be installed on Windows, whether running Windows 11, 10, 8.1, 8, or 7. Follow the above installation steps to install it.
How Do I Install Node.js on Windows 10 or Other Versions?
To install Node on Windows 10, use the nvm install lts
command in the terminal. Alternatively, follow the above installation steps of the tutorial for a detailed explanation.
Where Does Node Install on Windows?
Node.js is usually installed in the C:/Program Files/nodejs
directory.
Additional Resources
Here are some helpful links if you'd like to read in-depth about some of the technologies and concepts mentioned above.
- How do I create a HTTP server? (Source: Node.js)
- Chocolatey Software (Source: Chocolatey Software)
- node-gyp: Node.js native addon build tool on GitHub (Source: node-gyp GitHub repository)