Getting Started
20 minutes
linux
macos
windows

Installing Node.js

Learn what Node.js is, why you need it, and how to install it properly on any operating system.

What you'll accomplish

Have Node.js and npm installed and working on your computer.

Prerequisites

  • Completed "What is a Terminal?" lesson
  • Completed "Installing Git" lesson

What is Node.js?

Node.js is a program that runs JavaScript code on your computer. JavaScript was originally only for web browsers, but Node.js lets you use it anywhere.

Imagine JavaScript is a language, and your computer only understands machine code (1s and 0s).

  • In a browser: The browser translates JavaScript for you
  • Outside a browser: You need Node.js to translate

So when someone says "install Node.js," they mean "install the translator that lets your computer understand JavaScript."

Why Do You Need Node.js?

Almost every modern web development tool is built with JavaScript and runs on Node.js:

ToolWhat it does
npmDownloads and manages code packages (libraries)
Next.jsFramework for building websites
ViteTool for running your code during development
TypeScriptAdds type checking to JavaScript
ESLintFinds problems in your code

npm stands for "Node Package Manager." It comes automatically with Node.js.

Think of npm as an app store for code:

  • Want to add a calendar to your website? npm install calendar-library
  • Need to resize images? npm install image-resizer
  • Building with React? npm install react

There are over 2 million packages available. Instead of writing everything from scratch, you can use code that others have already written and tested.

How to Install Node.js

There are two approaches:

  1. Direct install (simpler, fine for beginners)
  2. Version manager (recommended for ongoing development)

We'll cover the version manager approach because it prevents many common problems.

Understanding npm

Now that you have Node.js installed, let's understand npm a bit better.

What is package.json?

When you start a new project, you'll create a package.json file. This file:

  • Lists your project's dependencies (the packages it needs)
  • Contains scripts for common tasks (like running your app)
  • Stores project metadata (name, version, description)

Imagine you're sharing a recipe:

  • Ingredients list = dependencies (what packages you need)
  • Instructions = scripts (how to cook/run the project)
  • Recipe name = project name

When someone downloads your project, they run npm install and npm reads the recipe to download all the ingredients automatically.

Common npm commands

CommandWhat it does
npm initCreate a new package.json
npm installInstall all packages listed in package.json
npm install <package>Add a new package to your project
npm run <script>Run a script defined in package.json
npm updateUpdate packages to latest compatible versions

You don't need to memorize these - you'll learn them naturally as you use them.

Test Your Installation

Let's verify everything works by creating a simple test:

Common Issues

Frequently Asked Questions

First: Make sure you opened a NEW terminal window after installation.

If using nvm:

  • macOS/Linux: Run nvm use --lts to make sure a Node.js version is active.
  • Windows: Run nvm use lts (nvm-windows uses different syntax—no -- prefix).

Still not working: Try reinstalling nvm/Node.js following the steps above.

npm downloads packages from the internet, so speed depends on your connection. If it's consistently slow:

  1. Check your connection: Try downloading something else
  2. Use a different registry: In some regions, mirrors are faster
  3. Consider pnpm: A faster alternative to npm (for advanced users)

Never use sudo npm install on Mac/Linux - it causes more problems.

If you're getting permission errors, nvm wasn't set up correctly. Reinstall nvm and Node.js following the steps above.

Common fix:

bash
# Remove any globally installed packages
rm -rf /usr/local/lib/node_modules
# Reinstall via nvm
nvm install --lts

No! You don't need to master Node.js. You just need it installed so that:

  • Your tools can run (they're built with JavaScript)
  • You can run the code that AI generates
  • You can install packages that your projects need

The AI will help you write the actual code. Think of Node.js as plumbing - it needs to work, but you don't need to understand how pipes work to use a sink.

JavaScript is the programming language (the words and grammar).

Node.js is the runtime that executes JavaScript outside a browser (the speaker who reads the words out loud).

In a browser, JavaScript runs automatically. Outside a browser, you need Node.js to run it.

Verify Your Understanding

You've completed this lesson if you can:

0/4

Next: Learn how to install Docker for containerized development environments.