Node.js ยท Chapter 2 of 43

Installing Node.js

To use Node.js, download and install it from nodejs.org. Installation includes both the `node` runtime and `npm`, the Node Package Manager.

After installing, you can verify everything works by checking version numbers from your terminal.

Installing

Download the LTS (Long Term Support) version for stability. Installers exist for Windows, macOS and Linux, and Linux users can also install via package managers like apt or nvm.

Verifying the install

Use `node -v` and `npm -v` in a terminal to confirm the versions installed. If these commands fail, Node isn't on your PATH.

Example 1 (javascript)
node -v
npm -v
Output
v20.11.0
10.2.4

These commands print the installed versions of Node.js and npm.

Example 2 (javascript)
node app.js
Output
Hello from Node.js!

Running a JavaScript file with the `node` command executes it using the Node.js runtime.

Key points

  • Download Node.js from nodejs.org (LTS recommended).
  • Installing Node.js also installs npm.
  • `node -v` checks the Node version.
  • Run any JS file with `node filename.js`.
๐Ÿ’ก Note: Consider using nvm (Node Version Manager) to switch between Node versions easily.

๐Ÿ“ Quick Quiz

1. What tool is installed alongside Node.js?

2. Which command checks the Node.js version?

3. How do you run a file called app.js with Node?