Zero, article directory
Nodejs 1. First introduction
1. First introduction to Node.js
(1) Review and reflection
- Components of JavaScript in the Browser
- Why JavaScript can be executed in the browser
- Why JavaScript can manipulate DOM and BOM
- JavaScript runtime environment in the browser
- Can JavaScript be used for back-end development?
(2) Introduction to Node.js
-
What is Node.js
Node.js
is aJavaScript 运行环境
based on the Chrome V8 engine.- Government location:https://nodejs.org/zh-cn/
-
JavaScript runtime environment in Node.js
-
浏览器
This is JavaScript前端运行环境
. -
Node.js
This is JavaScript后端运行环境
. -
Node.js
中无法调用 DOM 和 BOM
等浏览器内位API.
-
What Node.js can do: As a JavaScript running environment, Node.js only provides basic functions and APIs. However, based on the basic capabilities provided by Node.js, many powerful tools and frameworks have sprung up in endlessly. Therefore, learning Node.js can make front-end programmers qualified for more jobs and positions:
- Based on the Express framework (http://www.expressjs.com.cn/), you can quickly build web applications
- Based on the Electron framework (https://electronjs.org/), cross-platform desktop applications can be built
- Based on the restify framework (http://restify.com/), API interface projects can be quickly built
- Read, write and operate databases, create practical command line tools to assist front-end development, etc...
-
How to learn Node.js
- JavaScript learning path in the browser: JavaScript basic syntax + browser built-in API (DOM + BOM) + third-party libraries (jQuery, art-template, etc.)
- Node.js learning path:
JavaScript 基础语法
+Node.js 内置 API 模块
(fs, path, http, etc.) +第三方 API 模块
( express, mysql, etc.)
(3) Node.js installation
- Go to the Node.jsofficial download page and download the required version.
-
Distinguish the difference between
LTS
version andCurrent
versionLTS
: Long-term stable version. For追求稳定性的企业级项目
, it is recommended to install the LTS version of Node.js.Current
: Early adopter version of new features. For users of热衷于尝试新特性
, it is recommended to install the Current version of Node.js. However, there may be hidden bugs or security vulnerabilities in the Current version, so using the Current version of Node.js in enterprise-level projects is not recommended.
-
Window installation:
-
**Double-click installation:** Double-click the downloaded exe program to install it.
-
**Verify installation:**Open the terminal, enter the command
node –v
in the terminal, and press the Enter key to view the version number of the installed Node.js.
-
-
Linux installation
-
Please refer to Linux-related knowledgeLinux detailed explanation
-
Find the download address of on official website download page (note that node depends on the Linux system library, too The version of the library file that the new node depends on is newer. Centos7.9 here supports node 16, but node18 does not work):https://nodejs.org/download/release/v16.20.0/ node-v16.20.0-linux-x64.tar.xz
linux版本node
-
Create a new folder named under the folder on
linux
and enter this folder< /span>/usr/local
nodejs
[root@bluecusliyou ~]# cd /usr/local [root@bluecusliyou local]# mkdir nodejs [root@bluecusliyou local]# cd nodejs
- Download the installation package to the folder
[root@bluecusliyou nodejs]# wget https://nodejs.org/download/release/v16.20.0/node-v16.20.0-linux-x64.tar.xz
- Unzip the compressed package
[root@bluecusliyou nodejs]# tar -xvf node-v16.20.0-linux-x64.tar.xz [root@bluecusliyou nodejs]# ls node-v16.20.0-linux-x64 node-v16.20.0-linux-x64.tar.xz
- Establish a soft connection so that the command can be run globally
[root@bluecusliyou nodejs]# ln -s /usr/local/nodejs/node-v16.20.0-linux-x64/bin/node /usr/local/bin [root@bluecusliyou nodejs]# ln -s /usr/local/nodejs/node-v16.20.0-linux-x64/bin/npm /usr/local/bin
- Verify installation
[root@bluecusliyou nodejs]# node -v v16.20.0 [root@bluecusliyou nodejs]# npm -v 8.19.4
-
-
what is terminal
- Terminal (English: Terminal): It is specially designed for developers as a way to achieve human-computer interaction.
- Open the terminal in Windows system: shortcut key (
Windows徽标键 + R
) to open the run panel, entercmd 后直接回车
to open the terminal. - In the powershell or cmd terminal of Windows, we can use the following shortcut keys to improve the operating efficiency of the terminal:
- Use
↑
key to quickly locate the last executed command - Use
tab
key to quickly complete the path - Use
esc
key to quickly clear the currently entered commands - Enter
cls
command to clear the terminal
- Use
(4) Node.js executes JavaScript
- Open terminal
- enter:
node app.js