Installing Node.js
Why You Need Node.js on Your Machine
So far, you have learned that Node.js is a program that runs JavaScript outside the browser. To use it, you need to install it on your computer, just like you install any other application.
When you install Node.js, you actually get two tools at once:
- Node.js itself — the program that runs your JavaScript files.
- npm — the "Node Package Manager," a tool that helps you download and manage ready-made code written by others. We will meet npm properly in a later chapter.
Both tools work from the command line (also called the terminal), which is the text window where you type commands instead of clicking buttons.
Downloading the Installer
The official download page is at nodejs.org. You will see two versions offered:
| Version | Name | What it means |
|---|---|---|
| LTS | Long Term Support | Stable and reliable. Fixes are provided for years. |
| Current | Latest release | Has the newest features, but is supported for a shorter time and may change more often. |
For learning and for most real projects, choose LTS. It is the version most tutorials, books, and companies use. As a rule of thumb: pick "Current" only when a feature you need exists only there.
Download the installer for your operating system — Windows, macOS, or Linux — and run it. The installer walks you through a few screens. The default choices are fine; you can simply click "Next" until it finishes.
Checking That It Worked
Installing is only half the job — you should always verify. Open a new terminal window (opening a fresh one matters, because the terminal learns about new programs when it starts) and type:
node --versionYou should see something like v20.11.0. The exact numbers do not matter; any number starting with v18 or higher is fine for this tutorial. That line means Node.js is installed and the terminal can find it.
Now check npm the same way:
npm --versionA number like 10.2.4 means npm is ready too.
Where Node.js Lives
You do not need to know this to use Node.js, but it can be reassuring to know the installer copies the program to a standard place on your system, and it also tells your operating system where that place is. That "telling" is called adding Node.js to your PATH, which is the list of folders the terminal searches when you type a command. This is why you can type node from any folder and it just works.
One Version, Many Projects
A single Node.js installation can run many different projects on your computer. You do not install Node.js once per project. Later, when you start a project, you will create a project folder and npm will track that project's specific needs inside it — all using the one Node.js you just installed.
What Comes Next
With Node.js installed and verified, you are ready to run your first JavaScript file from the terminal. That is exactly what the next chapter covers.
Exercise
Which version of Node.js should most learners and most companies install, and why?
Show answer
The LTS (Long Term Support) version, because it is stable, receives fixes for a long time, and is what most tutorials and companies rely on. The Current version has newer features but is supported for a shorter time.
Exercise
You installed Node.js, but typing node --version gives "command not found." What is the most likely fix?
Show answer
Close the terminal and open a new one, so the terminal can find the freshly installed program. If that does not work, run the installer again or restart the computer.
Spotted a mistake, or code that does not work?