Node.js acts as a comprehensive runtime platform that is designed for executing JavaScript programs. It processes server-side scripts to generate dynamic content before delivering it to a web browser.
While, NPM, i.e., Node Package Manager serves as a repository as well as an application package manager to simplify the process of development and distribution of JavaScript code. It efficiently manages Node.js dependencies.
In this knowledge-based article, we’ll cover different techniques for installing and testing NPM and Node.js on Windows.
Fundamental Requirements
- An administrative-level user account with privileges for downloading and installing software applications.
- Access to a command line interface.
- A suitable code editor or IDE, i.e. Integrated Development Environment for writing and testing Node.js code.
Process for installing Node.js and NPM on Windows with Node.js installer
Installing a software program using GUI can seamlessly download the Node.js installer right from their official website.
Use the following steps to install Node.js and NPM on Windows using the Node.js installer:
Step 1: Download Node.js Installation Package
- In your web browser, go to the Node.js downloads section. Select the “Windows Installer” button to download the latest stable version which comes with LTS, i.e., long-term support. The installer also consists of the NPM package manager.
- Usually, the file is saved to the Downloads folder, by default.
- You can find different versions of Node.js and NPM, therefore make sure to select one of the most suitable options for your device and project needs.
- Make use of top tabs in order to navigate between LTS and the most recent version to experiment with the latest features.
- If you’re starting with Node.js or don’t require a particular version, select long-term support, i.e., LTS, because it is secure and proven.
Step 2: Installation of Node.js and NPM
Once you download the installer, please proceed with the steps outlined below:
- Start the installation process by just double-clicking the file that you’ve downloaded.
- Once you start the Node.js installation wizard, a welcome screen will appear.
- Hit the “Next” button to proceed.
- Read through the end-user license agreement and tick the checkbox to agree to the terms and conditions.
- After that, press the “Next” button in order to continue.
- The installer will ask you to select the installation path.Keep the installation path for a standard installation and Press the “Next” button to proceed.
- Choose the elements in order to add or delete from the setup. By default, the standard elements installed include Node.js, NPM, and corepack, which provide shortcuts for online documentation, and integrate these programs into your path.
- Personalize the configuration according to your needs or press the “Next” button to accept the default values in order to move forward.
- The next section indicates the total installation space needed for the installation alongside the available storage space.Press the “OK” button, in order to proceed. Try selecting a different disk or minimize the number of features to be installed if the installation isn’t possible.
- Decide whether you want to install added dependencies for configuring native modules. Several NPM modules can be developed from C/C++ and need extra tools such as Python, Visual Studio Build Tools, and Chocolatey in order to work effectively.
- If you make use of these modules, choose the appropriate checkbox and then press the “Next” button.
- Once you make this choice, it’ll initiate an installation script following the completion of the Node.js installation.
- For a more efficient installation process, you’ve got the option to skip this step and continue by selecting the “Next” button.
- Next, press the “Install” button, in order to launch the installation process.
- After this step, you’ll be prompted by the installer for administrative approval in order to go
- Continue with device modification.
- When asked, put in the administrator password and select Yes to proceed.
- The installation process might take a bit of time to complete. Once it is completed, the final screen showing a success message will appear.
- Press the “Finish” button to complete the installation process and exit the installation interface.
Important Note:
When you choose to install native tools in step 8, closing the installer will automatically initiate a Powershell script that will install all the specified tools.
Step 3: Verification of the Node.js Installation
In order to verify the successful installation of Node.js, execute the following command in a command prompt or PowerShell window:
node -v
The above command will display the version of the Node.js that you’ve installed on your device. For verifying the version of the NPM, run the following command:
npm -v
Important Note:
In case, if the NPM is either unrecognized by the command prompt or installed improperly, you might see the following error message:
npm: command not found
Verify whether the NPM is included in the system path, or check for the presence of any installed versions on your device.
A step-by-step guide to Installing Node.js and NPM on Windows via Chocolatey
Chocolatey is a popular Windows package manager that can be utilized to install different software programs like Node.js with NPM.
Here are the easy-to-follow steps to installing Node.js and NPM via Chocolatey.
Important Note:
Remember that Chocolatey isn’t present on Windows by default, therefore, if you want to install it, refer to our comprehensive guide for seamless installation of Chocolatey on your Windows OS:
Step 1: Installation of Node.js and NPM
In order to launch the installation command, please proceed with the following steps:
- Using the administrator access launch the command prompt.
- Execute the following command for installing Node.js and NPM:
choco install nodejs
When you’re asked to execute the installation script, select “y” and the “Enter” button to carry on with the installation process. Wait until the installation process is completed before moving ahead.
3. Update the environment variables in order to add Node.js and NPM to your PATH, with the help of the following command:
refreshenv
This command will reset the environment variables, thereby allowing the terminal to run both programs from the terminal.
Step 2: Test the Successful Installation Of Node.js And NPM
To confirm the successful installation of Node.js, execute the following command in a completely new command prompt:
node -v
Check the correct installation of the NPM package with:
npm -v
Both of these commands will output the program version.
Confirm Node.js Installation
Using different methods you can confirm the installation of a Node.js installation. One of the most easiest ways to write a Hello World JavaScript program and execute it with the help of Node.js:
1. Start a text editor or IDE [integrated development environment]
2. Insert the following code in your file:
console.log("Hello, world!")
This basic JS program will output “Hello, world!” on the screen.
3. Save the script by using a .js extension.
4. In order to observe the final output, execute the program through an integrated development environment. Or else, you can go to the directory containing the file and run the following command:
node [file_name].js
The command will display a message on the console, confirming that the Node.js installation has been completed successfully.
Now, you’ve successfully installed the Node.js framework and the NPM package manager and at the same time, taken the first step towards executing your first JavaScript program using Node.js.