Lesson 2 of 50 – Installing Node.js
4%
4%

How to Install Node.js

Node.js must be installed on your computer before you can execute JavaScript programs using Node.js.

In this lesson, we will learn how to download Node.js, install it on Windows, and check whether the installation was successful.

Important: Node.js includes NPM, which helps you install and manage packages used in Node.js projects.

What Do We Need?

Requirements
  • A computer running Windows, macOS, or Linux.
  • An internet connection to download Node.js.
  • A web browser to visit the official Node.js website.
  • A text editor such as Visual Studio Code (optional).

Step 1: Visit the Official Node.js Website

Open your browser and visit the official Node.js website.

Official Website

Website: https://nodejs.org/

Download Node.js only from the official website to reduce the risk of downloading an unsafe installer.

Step 2: Choose a Node.js Version

The Node.js website provides release options. For most beginners, the LTS (Long-Term Support) release is a good choice because it receives long-term maintenance and is generally suitable for learning and regular development.

LTS Version

Choose the current LTS release displayed on the official Node.js website. The version number may change over time.

Tip: Avoid choosing an old release unless your project specifically requires it.

Step 3: Download Node.js for Windows

If you are using Windows, select the Windows installer provided on the official download page.

  1. Open nodejs.org.
  2. Choose the recommended LTS release.
  3. Select the Windows installer suitable for your computer.
  4. Wait for the installer file to download.
The installer is commonly provided as an .msi file for Windows.

Step 4: Run the Installer

After downloading the installer, follow these steps:

Installation Steps
  1. Open the downloaded installer file.
  2. Click Next on the setup screen.
  3. Read and accept the license agreement.
  4. Choose the installation folder or keep the default location.
  5. Keep the standard features selected.
  6. Click Install.
  7. Approve the installation if Windows requests permission.
  8. Click Finish when the installation completes.
Installation Tip: For a standard beginner setup, keeping the default installation options is usually sufficient.

Step 5: Open Command Prompt

After installation, open Command Prompt on Windows.

  1. Press Windows + R.
  2. Type cmd.
  3. Press Enter.

You can also search for Command Prompt in the Windows Start menu.

Step 6: Check the Node.js Version

Type the following command and press Enter:

Node.js Version Command
node -v

This command displays the version of Node.js installed on your computer.

Example Output
Command Prompt
v22.15.0

This is only an example. Your installed version may be different.

Step 7: Check the NPM Version

NPM is installed along with the standard Node.js Windows installer. To check its version, run:

NPM Version Command
npm -v

This command displays the installed version of NPM.

Example Output
Command Prompt
10.9.2

The displayed version may differ depending on the Node.js release installed on your computer.

Step 8: Create Your First Node.js File

Now that Node.js is installed, let's create a simple JavaScript file.

1. Create a Project Folder

Create a folder named MyNodeProject.

2. Create a JavaScript File

Inside the folder, create a file named app.js.

3. Write the Following Code
app.js
console.log("Node.js is installed successfully!");
4. Run the Program

Open Command Prompt in your project folder and run:

node app.js
Output
Program Output
Node.js is installed successfully!
💡 Remember
If the program displays the message in the terminal, Node.js is working correctly for this basic example.

Common Installation Problems

Error: 'node' is not recognized

This can happen if Node.js is not installed correctly or its installation directory is missing from the PATH environment variable.

Try these steps:
  1. Close Command Prompt and open it again.
  2. Check whether Node.js installation completed successfully.
  3. Confirm the Node.js installation directory is included in PATH.
  4. If needed, rerun the installer and repair the installation.
Error: 'npm' is not recognized

Restart the terminal and check your installation. If the error continues, verify that the Node.js installation directory and the NPM command directory are configured correctly.

Practical Assignment

Practice Tasks
  1. Visit the official Node.js website.
  2. Download and install the current LTS release.
  3. Open Command Prompt.
  4. Check the Node.js version using node -v.
  5. Check the NPM version using npm -v.
  6. Create a folder named MyNodeProject.
  7. Create an app.js file inside the folder.
  8. Display your name using console.log().
  9. Run your program using node app.js.
🎯 Lesson Goal
By the end of this lesson, you should be able to install Node.js, verify Node.js and NPM versions, and execute a basic JavaScript file.

🧠 Quiz

1. Which website should you use to download Node.js?

2. Which command checks the Node.js version?

3. Which command runs the app.js file?