Node.js is not a programming language. It is a JavaScript running environment based on the Chrome V8 engine. In this environment, js code can be run. This environment is implemented based on the V8 engine and is very lightweight in terms of I/O. It can hold many open connections while handling a large number of requests, and only takes up a small amount of memory. Its design goal is to ensure responsiveness, just like the browser. [Recommended: node.js video tutorial]
official website: English and Chinese
LTS : long-term stable version, project development recommends downloading this version
Current : the latest early adopter version. The latest version contains some new features. If you want to learn the latest features, you can download this version. The latest version may have some unknown bugs.
Click the button on the left (the one with the LTS logo) and it will download immediately. Note: Select the corresponding installation file for different systems.
Find the installation package you downloaded (different versions have different installation packages).
Double-click the installation file to start. Installation (foolish installation, all the way next
)
Remember to use an English path for the installation directory, and do not have Chinese characters in the path.
, open the terminal, enter the node -v command in the command window of the terminal (there is a space after node), and then Enter. If the version number of Node.js can be printed out in the terminal window (version number v16.14.2 in the picture), it means that Node.js has been installed successfully.
1. Run in the terminal window (not important)
Note: Not important, similar to the "Console" panel of the browser debugging tool, only suitable for running a small amount of test code, just take a look and
operate Steps:
Open any terminal, directly enter the node command and press Enter
to execute your JS code. Press Enter to execute and press
"Ctrl+C" twice to exit.
2. Use the node command to execute js files.
This is more common, and you can run and write js
Operation steps
for js code in the file
:Open the terminal and pay attention to the path of the terminal. Your js file must be found in the path of the terminal.
Enter " node 要执行的js文件
"
node file name.js
When executing the file, you need to ensure that node xxx.js
is in this format.
node can only run JS code, and can only run js code.
(1) node space a js file // call the node program and run a js file (2) clear or cls // clear the interface (3) ls or dir // view the list (list) (4) cd directory name // Enter the directory (5) cd .. // Return to the previous directory (6) cd // Return directly to the root directory (7) Ctrl+C // Stop the Node program ( 8) After inputting part of the file name, press the Tab key // to complete the file name or directory name. Multiple tabs will switch (9) ↑ ↓ up and down arrows // switch historical input
1. When choosing the version to download for project development, remember to choose the LTS long-term stable version. The latest version may have some unknown bugs.
2. Do not include Chinese characters in the installation path. After installation, enter node-v in the terminal to check whether the installation is successful.
3. Node can only run js files. When executing js files, remember to pay attention to the path of the terminal.
Note that there is no DOM in NodeJS. BOM, and there is no window object.
The above is a detailed explanation of how to install, download and run Node.js (with commonly used commands). For more information, please pay attention to other related articles on the PHP Chinese website!