Lesson 6 of 60 – Installing Node.js
10%

Installing Node.js

Before creating and running a modern React development project, you will commonly need Node.js and a package manager such as npm. Node.js provides a JavaScript runtime outside the browser, while npm is commonly used to install and manage JavaScript packages.

Note: Node.js is not React. React is a JavaScript library, while Node.js provides the runtime and tooling environment commonly used when developing React applications.

1. What is Node.js?

Node.js is a JavaScript runtime that allows JavaScript code to run outside a web browser.

JavaScript
    ↓
Node.js Runtime
    ↓
Computer

Node.js is commonly used for development tools, servers, command-line programs, and JavaScript-based tooling.

2. Why is Node.js Used with React?

React code is ultimately used to build browser-based user interfaces, but React development projects commonly use Node.js-based tools during development.

Node.js
   ↓
Package Manager
   ↓
React Project Tools
   ↓
Development
   ↓
React Application

3. What is npm?

npm is a package manager commonly used with Node.js. It can install packages, manage project dependencies, and run commands defined by a project's configuration.

Node.js
   +
npm
   ↓
JavaScript Project

4. Node.js and npm Relationship

Node.js provides the runtime, while npm is commonly used to manage JavaScript packages and project commands.

Node.js
 ├── JavaScript Runtime
 │
 └── npm
      ├── Install Packages
      ├── Manage Dependencies
      └── Run Scripts

5. Check Whether Node.js is Installed

After installing Node.js, you can check the installed version from a terminal.

node --version

If Node.js is installed correctly, the command displays a version number.

6. Check the npm Version

You can also check the npm version using the terminal.

npm --version

A version number indicates that npm is available from your command line.

7. Download Node.js

Node.js can be downloaded from the official Node.js website.

Visit the Node.js download page and choose the installer appropriate for your operating system.

Official Website
       ↓
Download Node.js
       ↓
Choose Operating System
       ↓
Install

8. Node.js on Windows

On Windows, Node.js can be installed using the Windows installer provided by the Node.js project.

Windows
   ↓
Node.js Installer
   ↓
Installation
   ↓
Command Prompt / PowerShell
   ↓
node --version

9. Node.js on macOS

Node.js can also be installed on macOS using an appropriate installer or other supported installation methods.

macOS
  ↓
Install Node.js
  ↓
Terminal
  ↓
node --version

10. Node.js on Linux

Node.js can be installed on Linux using installation methods appropriate for the particular Linux distribution.

Linux
  ↓
Install Node.js
  ↓
Terminal
  ↓
node --version

Installation commands can differ between Linux distributions.

11. Node.js Installer

On systems using an installer, the installation process normally provides a series of setup screens.

Installer
   ↓
License
   ↓
Installation Location
   ↓
Features
   ↓
Install
   ↓
Finish

12. Installation Location

During installation, Node.js files are placed in an installation directory selected by the installer.

For most beginners, the default installation location is suitable unless there is a specific reason to change it.

13. PATH Environment Variable

The operating system uses the PATH environment variable to locate executable programs from the command line.

Terminal
   ↓
node --version
   ↓
PATH
   ↓
Node.js Executable

A correctly configured PATH allows commands such as node and npm to be used from the terminal.

14. Open Command Prompt

On Windows, you can use Command Prompt or PowerShell to execute Node.js commands.

Windows
   ↓
Command Prompt / PowerShell
   ↓
node --version

15. Open Terminal on macOS or Linux

On macOS and Linux, the Terminal application can be used to execute Node.js and npm commands.

Terminal
   ↓
node --version
npm --version

16. Verify Node.js Installation

After installation, open a new terminal and run:

node --version

You should see the installed Node.js version.

vXX.XX.X

The exact version displayed depends on the version installed on your computer.

17. Verify npm Installation

Run the following command:

npm --version

If npm is correctly available, the terminal will display its version number.

18. Test Node.js with a Simple Program

You can test Node.js by creating a JavaScript file.

console.log("Hello Node.js");

Save the file as test.js and run:

node test.js

The terminal should display:

Hello Node.js

19. Creating a Project Folder

Before creating a React project, you can create or choose a folder where your projects will be stored.

mkdir react-projects
cd react-projects

The exact commands can vary depending on your operating system and terminal.

20. npm Package Management

npm can download and manage packages required by a JavaScript project.

npm install package-name

The package information is recorded in the project's package configuration.

21. package.json

A JavaScript project commonly contains a package.json file. It stores project information, scripts, and dependency declarations.

{
    "name": "my-react-app",
    "scripts": {},
    "dependencies": {}
}

22. node_modules Folder

When packages are installed, their files are commonly stored in a node_modules directory.

Project
 |
 +-- package.json
 |
 +-- node_modules/
 |
 +-- src/

This directory can contain many files because packages may have their own dependencies.

23. npm Scripts

Projects can define commands in the scripts section of package.json.

{
    "scripts": {
        "dev": "..."
    }
}

The command can then be executed using:

npm run dev

24. Node.js is Not a Browser

Node.js is not a web browser. It provides a JavaScript runtime for executing JavaScript outside the browser.

Browser Node.js
Runs JavaScript in a browser environment Runs JavaScript outside the browser
Provides browser APIs such as DOM Provides Node.js APIs
Displays web pages Provides runtime and development capabilities

25. Common Installation Problem

If the terminal shows an error such as:

'node' is not recognized

Node.js may not be installed correctly or its executable may not be available through the system PATH.

After installation, opening a new terminal can also be necessary so that environment changes are recognized.

26. Check Node.js from Any Folder

A correctly configured Node.js installation should normally allow the node command to work from a terminal without navigating to the Node.js installation directory.

cd Desktop
node --version

If the version is displayed, the command is available from that location.

27. Node.js for React Development

Node.js is commonly part of the React development environment. It allows developers to use JavaScript tooling and package managers needed by React projects.

Node.js
   ↓
npm
   ↓
React Dependencies
   ↓
Development Tools
   ↓
React Application

28. Installation Checklist

  • Download Node.js from its official source.
  • Install Node.js for your operating system.
  • Open a new terminal after installation.
  • Run node --version.
  • Run npm --version.
  • Confirm that both commands work.
  • Choose a folder for your React projects.

29. Complete Setup Flow

Download Node.js
       ↓
Install Node.js
       ↓
Open Terminal
       ↓
node --version
       ↓
npm --version
       ↓
Create Project Folder
       ↓
Ready for React Development

30. Summary of Node.js Installation

Node.js is an important part of many modern JavaScript development environments. For React development, it is commonly used with npm and other tools to install dependencies, run development commands, and build applications.

Node.js
   +
npm
   ↓
JavaScript Tooling
   ↓
React Development

After verifying node --version and npm --version, you are ready to move to the next step: setting up your development environment.

📌 Key Points

  • Node.js is a JavaScript runtime.
  • Node.js allows JavaScript to run outside the browser.
  • npm is commonly used to manage JavaScript packages.
  • React is different from Node.js.
  • Node.js is commonly used for React development tooling.
  • Use node --version to check the Node.js installation.
  • Use npm --version to check the npm installation.
  • The PATH environment variable helps the terminal locate executables.
  • package.json stores important project configuration and dependencies.
  • node_modules contains installed project dependencies.
  • Node.js can be installed on Windows, macOS, and Linux.
  • After installation, you can begin setting up a React development environment.

🧠 Quick Quiz

Question: Which command is used to check the installed Node.js version?