We use cookies to enhance your experience on the site
CodeWorlds

Installing Node.js and npm

Before we start using React, we need to install the basic tools - Node.js and npm (Node Package Manager). It's like preparing oxygen supplies and fuel before heading into space.

What is Node.js?

Node.js is a platform that allows you to run JavaScript outside the browser. Traditionally, JavaScript was a language that only ran in browsers, but Node.js changed that by enabling JavaScript to run on servers and in developer tools as well.

For a React developer, Node.js is essential for:

  • Running a local development server
  • Using a package manager (npm or yarn)
  • Building and compiling applications
  • Running tools like linters, formatters, and tests

What is npm?

npm (Node Package Manager) is the world's largest software package registry. It's a repository containing thousands of packages and libraries that you can add to your project. Imagine a gigantic catalog of spare parts for spaceships - whatever you need, you'll probably find it in npm.

Node.js and npm installation process

For Windows:

  1. Visit the official Node.js website
  2. Download the LTS (Long-Term Support) version - this version is the most stable and recommended for most users
  3. Run the downloaded installer and follow the instructions
  4. The installer will automatically install both Node.js and npm

For macOS:

Option 1: Installer

  1. Visit Node.js and download the installer for macOS
  2. Run the installer and follow the instructions

Option 2: Homebrew (recommended if you already have Homebrew)

  1. Open terminal
  2. Type:
    brew install node

For Linux:

Ubuntu/Debian:

1sudo apt update
2sudo apt install nodejs
3sudo apt install npm

Fedora:

1sudo dnf install nodejs

Verifying the installation

After completing the installation, open the terminal (or command prompt) and verify the installation by typing:

1node -v
2npm -v

You should see version numbers, for example

v16.15.0
for Node.js and
8.5.5
for npm. If you see this information, congratulations! Your spaceship is ready for the journey.

Alternative package managers

Besides npm, there are also alternative package managers you can consider:

Yarn

Yarn is a package manager created by Facebook that offers faster package downloading and better dependency management.

Installation:

1npm install -g yarn

pnpm

pnpm is an efficient package manager that saves disk space by sharing common dependencies between projects.

Installation:

1npm install -g pnpm

In this course, we'll mainly use npm, but all commands have their equivalents in Yarn and pnpm.

Next steps

Now that you have Node.js and npm installed, you're ready to create React applications! In the next lesson, we'll learn how to create a new React project using Vite.

Go to CodeWorlds