Appearance
Installing Node.js
Since the Node.js platform runs JavaScript code on the backend, you must first install the Node environment on your machine.
The latest version of Node.js is currently 22.3.0, and the LTS version is 20.14.0. For stable environments, such as servers running Node for an extended period, it is recommended to choose the LTS version. For local development and testing, the latest version can be selected.
To install Node.js, first, download the installer for your platform from the official Node.js website. Beginners are advised to choose the Prebuilt Installer, select the version, then choose the operating system, and finally select the CPU type before clicking Download:
Experienced developers can choose the Package Manager, which allows local installation of multiple different versions of Node and switching between them.
When installing on Windows, be sure to select all components, including checking Add to Path.
After installation, in a Windows environment, please open the Command Prompt and enter node -v
. If the installation was successful, you should see output like v22.3.0
:
C:\Users\IEUser> node -v
v22.3.0
Continue by entering node
in the Command Prompt; you will enter the Node.js interactive environment. In this environment, you can input any JavaScript statement, for example, 100 + 200
, and after pressing Enter, you will see the output result.
To exit the Node.js environment, press Ctrl+C twice.
npm
Before we officially start learning Node.js, let's get to know npm.
What is npm? npm is actually the package manager for Node.js.
Why do we need a package manager? Because when developing on Node.js, we will use a lot of JavaScript code written by others. If we want to use a package written by someone else, searching the official website by name, downloading the code, unzipping it, and then using it is very cumbersome. Thus, a centralized management tool was created: developers package their modules and upload them to the npm website. If you want to use it, you can directly install it through npm without worrying about where the code is stored or how to download it.
More importantly, if we want to use module A, which depends on module B, and module B depends on modules X and Y, npm can download and manage all the dependent packages based on these relationships. Otherwise, managing everything manually would be both troublesome and error-prone.
So where is npm?
Actually, npm is installed automatically when you install Node.js. You can check its version by entering npm -v
in the Command Prompt or terminal, and you should see similar output:
C:\>npm -v
10.8.0
If you enter npm
directly, you will see output similar to this:
C:\> npm
Usage: npm <command>
where <command> is one of:
...
The above text indicates that npm requires a command to follow. For now, we don’t need to worry about these commands; we will cover them one by one later. For the moment, you only need to ensure that npm is installed correctly and is operational.
Summary
Please install the Node.js environment on your machine and ensure that both node and npm are functioning properly.