73  73. Step 0: Install Node.js and npm

As of Oct 22, 2026 · Official docs: Node.js · npm

In this project we will be using Node.js and the npm tool. Below we will explain what they are and how they are used. For now though, let’s first make sure that you have the necessary software installed.

73.1 What is Node.js?

Node.js is a JavaScript runtime environment. In other words, it is a program that runs JavaScript code.

JavaScript was originally created to run inside web browsers to make webpages more interactive - e.g. dropdown menus, popup menus, tell users that they didn’t fill out a form properly, etc. It is still used inside browsers in these ways and others. To run JavaScript in a browser, you do NOT need Node.js.

Node.js is used to run JavaScript code outside of a browser. In this way you can use JavaScript to create any type of program. This made JavaScript more similar to other languages such as Python, Java, R, etc. Node.js was the first widely used way to run JavaScript outside the browser, on servers and on your own computer. Today there are other JavaScript runtimes, such as Bun and Deno. However, Node.js is still very popular.

73.2 What are Packages?

When developers build software, they often need to solve common problems: connecting to databases, handling dates and times, processing images, and so on. Rather than writing this code from scratch every time, developers create reusable bundles of code called packages (sometimes also called libraries).

If you’ve used R or Python, you’re already familiar with this concept: - In R, you might use packages like ggplot2 for visualization or dplyr for data manipulation - In Python, you might use pandas for data analysis or requests for making HTTP requests

JavaScript packages work the same way. For example, instead of writing complex code to handle dates, you could use a package like date-fns that someone else has already written and tested.

73.3 What is a Package Manager?

A package manager is a tool that helps you install, update, and manage packages. When you use R, you might run install.packages("ggplot2"). In Python, you use pip install pandas. These commands use package managers to:

  1. Download the package from a central repository
  2. Install it in the right location on your computer
  3. Keep track of which packages your project uses
  4. Manage dependencies (packages that other packages need to work)

73.4 What is npm (Node Package Manager)?

npm stands for “Node Package Manager”. It is a package manager that comes with Node.js. When you install Node.js, npm comes with it automatically.

Later we will cover more about how to use npm. For now though we just want you to understand what it is. npm connects to a massive online repository of JavaScript packages, called the npm registry. When you need a package, you simply run the following command from the CLI (e.g. Bash) to have npm download the package and make it available for your project to use.

npm install package-name

The npm registry is one of the largest package ecosystems in the world, with millions of packages available. This means that for almost any problem you’re trying to solve, someone has probably already created a package to help.

73.5 OK, so how do I use npm?

We’ll cover this a little later, in Step 2: Installing the Node.js packages with npm.

Practice Questions

Easy

Question 1 · Multiple choice

What is Node.js?

  1. A web browser
  2. A JavaScript runtime environment: a program that runs JavaScript code outside a browser
  3. A package of reusable JavaScript code
  4. A database

b. Node.js runs JavaScript programs outside a browser. It isn’t a browser (a); a package (c) is a bundle of code that other programs use; and Node.js is not a database (d).

Question 2 · True or false

After you install Node.js, you have to install npm separately.

False. npm is installed automatically when you install Node.js. You only need to install Node.js.

Question 3 · Write the command

Write the command that checks whether npm (and therefore Node.js) is installed on your computer.

npm -v

If npm is installed, this prints its version number. If you get an error instead (for example “command not found”), npm and Node.js are most probably not installed.

Question 4 · Short answer

What does “npm” stand for, and what is it used for?

Node Package Manager. It installs and manages JavaScript packages for your projects, downloading them from the huge online npm registry.

Medium

Question 5 · Matching

Match each language with a command that installs a package for it.

Language Command
1. R A. pip install pandas
2. Python B. npm install date-fns
3. JavaScript (Node.js) C. install.packages("ggplot2")

1 → C, 2 → A, 3 → B.

Question 6 · Short answer

A package manager does four jobs. List them.

  1. It downloads packages from a central online repository.
  2. It installs them in the right location on your computer.
  3. It keeps track of which packages your project uses.
  4. It manages dependencies: packages that other packages need in order to work.

Question 7 · Multiple choice

Which of these does not need Node.js?

  1. Making a drop-down menu work on a web page in your browser
  2. Running npm install to download packages
  3. Running a JavaScript program from the terminal, outside the browser
  4. Using JavaScript to build a program that isn’t a web page, the way you might use Python or R

a. JavaScript inside a web page is run by the browser itself, so no Node.js is needed. npm (b) comes with Node.js and needs it in order to run, and (c) and (d) are exactly what Node.js was created for: running JavaScript outside a browser.

Question 8 · Short answer

Why do developers use packages instead of writing all of their code themselves? Give an example from the page.

Many problems come up again and again (handling dates and times, connecting to databases, processing images), and someone has already written and tested code that solves them. Using a package saves time and avoids bugs. Examples: date-fns for dates in JavaScript, pandas in Python, ggplot2 in R.

Question 9 · True or false

Node.js is the only JavaScript runtime environment.

False. Today there are others, such as Bun and Deno. Node.js is still very popular, and it is the one this tutorial uses.

Hard

Question 10 · Scenario

Sam installs Node.js on his Windows laptop. In the Git Bash window he had opened before the installation, he types npm -v and gets an error saying the command was not found. What should he try, and why might it help?

He should close that terminal, open a new one, and run npm -v again (the page tells you to do exactly this after installing). A terminal that was already open may not know about programs installed after it started: for example, the installer may have updated the PATH (the list of folders where the shell looks for commands), and a terminal reads that setting when it starts. If a new terminal still can’t find npm, he should ask an AI assistant or a knowledgeable person for help.

Question 11 · Scenario

Package A needs package B in order to work. You run npm install A. What will npm do about package B, and why is that helpful?

B is a dependency of A. Managing dependencies is one of a package manager’s jobs, so npm also downloads and installs B (and anything B itself needs). You don’t have to hunt down and install every required package by hand, and A won’t fail because a piece is missing.

Question 12 · Long answer

Explain how Node.js, npm and a package (such as date-fns) relate to each other. Use an analogy with R or Python.

Model answer:

  • Node.js runs JavaScript programs outside the browser, just as R runs R code and Python runs Python code on your computer.
  • A package such as date-fns is a reusable bundle of code that someone else wrote and tested, like ggplot2 in R or pandas in Python.
  • npm is the package manager: it downloads packages from the online npm registry and installs them for your project, like install.packages() in R or pip in Python. npm comes bundled with Node.js.

Together: npm installs the packages, your code uses them, and Node.js runs the JavaScript. A good answer explains all three roles and how they work together.

© 2025-2026 Y. Rosenthal. All rights reserved.