Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. Node.js Dictionary
  3. [Setup] Node.js Development Environment

[Setup] Node.js Development Environment

This page explains how to install Node.js and set up a development environment. Node.js is a runtime environment for executing JavaScript on the server side. Once installed, you can run JavaScript files directly from the command line using the node command.

Installing Node.js

You can download an installer for Node.js from the official site (nodejs.org). The LTS (Long Term Support) version has guaranteed long-term support and is suitable for production use.

OSInstallation method
WindowsDownload the LTS installer (.msi) from nodejs.org and run it. Follow the wizard to complete the installation.
macOS (official)Download the LTS installer (.pkg) from nodejs.org and run it.
macOS (Homebrew)Run brew install node in the terminal. Homebrew is a package manager for macOS. If it is not installed, follow the instructions at brew.sh.

Verifying Installation on Windows

After installation, open Command Prompt or PowerShell and run the following.

node --version
v20.14.0
npm --version
10.7.0

If version numbers are displayed, the installation was successful.

Verifying Installation on macOS

After installation, open a terminal and run the following.

node --version
v20.14.0
npm --version
10.7.0

If version numbers are displayed, the installation was successful.

Basics of npm and npx

Installing Node.js also installs npm (Node Package Manager) and npx.

CommandDescription
npmThe package management tool for Node.js. Used to install, remove, and manage versions of external libraries.
npxA command for running packages directly without installing them. Allows you to try various CLI (Command Line Interface — a screen where you type commands with a keyboard) tools without a global install.

The following example uses npx to check the Node.js version.

npx node --version

To update npm itself, run the following.

npm install -g npm@latest

Version Management with nvm

When working on multiple projects, different projects may require different versions of Node.js. In such cases, nvm (Node Version Manager) lets you switch between Node.js versions as needed.

On macOS / Linux, install nvm with the following command.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

After installation, restart the terminal and confirm that nvm is available.

nvm --version
0.39.7
CommandDescription
nvm install --ltsInstalls the latest LTS version.
nvm install 20.14.0Installs the specified version.
nvm use 20.14.0Switches to the specified version.
nvm lsLists all installed versions.
nvm alias default 20.14.0Sets the default version.
Example of version management with nvm
nvm install --lts
Now using node v20.14.0 (npm v10.7.0)
nvm install 18.20.3
Now using node v18.20.3 (npm v10.7.0)
nvm ls
       v18.20.3
->     v20.14.0
nvm use 18.20.3
Now using node v18.20.3 (npm v10.7.0)

On Windows, nvm-windows can be used as an alternative to nvm.

Your First Node.js Program

Once the environment is ready, write and run your first program. Save the following content as hello.js in a text editor.

hello.js
// Store KOF fighters in an array
var fighters = ["Yagami Iori", "Kusanagi Kyo", "Terry Bogard", "Blue Mary", "Andy Bogard"];

// Print the name of each fighter to the console
fighters.forEach(function(name) {
    console.log("Hello, " + name + "!");
});
node hello.js
Hello, Yagami Iori!
Hello, Kusanagi Kyo!
Hello, Terry Bogard!
Hello, Blue Mary!
Hello, Andy Bogard!

Uninstalling Node.js

The method for uninstalling Node.js depends on how it was installed.

OS / MethodUninstall procedure
WindowsGo to Settings → Apps → Installed apps, select Node.js, and click Uninstall.
macOS (official installer)Run sudo rm -rf /usr/local/lib/node_modules /usr/local/bin/node /usr/local/bin/npm in the terminal.
macOS (Homebrew)Run brew uninstall node in the terminal.
Via nvmUse nvm uninstall 20.14.0 to remove a specific version. To remove nvm itself, run rm -rf "$NVM_DIR".

Recommended Text Editors

Here are text editors and IDEs useful for Node.js development.

ToolFeatures
VSCodeCurrently the most widely used editor. A rich selection of extensions needed for Node.js development (ESLint, Prettier, etc.) is available. Supports Windows / macOS / Linux. Free.
Sublime TextExtremely lightweight with a simple interface that keeps the focus on coding. Supports Windows / macOS / Linux.
WebStormA JavaScript / Node.js dedicated IDE (Integrated Development Environment — a development tool that combines code editing, execution, and debugging in one) by JetBrains. Features advanced code analysis, refactoring, and debugging capabilities. Paid.

Common Mistakes

Common Mistake 1: node command not found (PATH not configured)

If running node --version after installation displays command not found, it means Node.js's installation directory is not included in the shell's PATH.

Command line (NG)
node --version
zsh: command not found: node

On Windows, closing and reopening Command Prompt after installation lets the PATH take effect. On macOS / Linux when using nvm, restart the terminal or check that the nvm initialization lines have been added to the shell configuration file (~/.bashrc or ~/.zshrc).

~/.zshrc (lines required when using nvm)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

If these lines are present in the configuration file, restart the terminal or run source ~/.zshrc to apply them.

Common Mistake 2: Installed Node.js with nvm but the version changes every time a new terminal is opened

nvm switches versions per terminal session. Without setting a default version, a different version may become active when a new terminal is opened.

Command line (NG)
nvm use 20.14.0
Now using node v20.14.0 (npm v10.7.0)
node --version
v20.14.0

The above is only effective for the current terminal session. Opening a new terminal reverts to a different version.

Command line (OK)
nvm alias default 20.14.0
default -> 20.14.0 (-> v20.14.0)
node --version
v20.14.0

Setting the default version with nvm alias default causes the specified version to be automatically activated whenever a new terminal is opened.

If you find any errors or copyright issues, please .