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: 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 be downloaded 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 the installation (foolish installation, all the waynext
)
Remember to use the 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 press 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 successfully installed
1. Run in the terminal window (not important)
Note: Not important, similar to the "Console" of the browser debugging tool The panel is only suitable for running a small amount of test code, just take a look
Operation steps:
Open any terminal, directly enter the node command and press Enter
Execute your JS code, press Enter to execute
Press "Ctrl C" twice to exit
2. Use the node command to execute the js file
This is more commonly used. You can run the js code written in the js file
Operation steps:
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 file to be executed
"
node 文件名.js
When executing the file , need to ensure that node xxx.js
This format
node can only run JS code, can only run js code
(1)node 空格 某个js文件 // 调用 node 程序,运行某个js文件 (2)clear 或者 cls // 清空界面 (3)ls 或者 dir // 查看列表(list) (4)cd 目录名 // 进入到目录中去 (5)cd .. // 返回上一级目录 (6)cd \ // 直接回到根目录 (7)Ctrl+C // 停止 Node 程序 (8)输入部分文件名后按下 Tab 键 // 补全文件名 或 目录名, 多次tab会进行切换 (9)↑ ↓ 上下箭头 // 切换历史输入
1. When choosing the version to download for project development, remember to choose the LTS long-term stable version. The latest version may be There will be some unknown BUG.
2. Do not have 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 Pay attention to the path of the terminal
Please note that there is no DOM, no BOM, and no window object in NodeJS
The above is the detailed content of Detailed explanation of how to install, download and run Node.js (with commonly used commands). For more information, please follow other related articles on the PHP Chinese website!