Environment configuration of Node.js
Before environment configuration, let's review the components of JavaScript in the browser: It can be divided into two parts 核心语法 (循环,函数...)
and web API (DOM BOM)
. As shown in the following figure:
Review why JavaScript code can be executed in the browser:
Because different browsers contain different JavaScript parsing engines:
举个栗子:
Chrome allows us to develop the most commonly used browser, why can it become the most commonly used browser, and where is it friendly to us? In fact, Google Chrome's V8 parsing engine is the best engine for parsing JavaScript code among many browsers.
List the analysis engines of the current mainstream browsers:
- Chrome browser => V8
- Firefox browser = "OidnMonkey (Odin Monkey)
- Safari browser => JScode
- IE browser = "charkra (Chakra)
tips:
The V8 parsing engine of Chrome browser is the nicest!
Why JavaScript can manipulate DOM and BOM
Because each browser has built-in API functions such as DOM and BOM, JavaScript in the browser can call them.
The JavaScript runtime in the browser
Using Chrome as an example
Summarize:
- The V8 engine is responsible for parsing and executing JavaScript code.
- The built-in API is a special interface provided by the running environment, which can only be called in the running environment to which it belongs.
What is Node.js
Node.js 是
One based on the Chrome V8 engine JavaScript 运行环境
.
Node URL:https://nodejs.org/zh-cn/
JavaScript runtime environment in Node.js
- Browsers are JavaScript
前端运行环境
. - Node.js is JavaScript
后端运行环境
. 无法调用
In-browser APIs like DOM and BOM in Node.js.
What Node.js can do
Based on node, we can use many frameworks to develop faster:
- Based on the Express framework (
http://www.expressjs.com.cn/
), you can quickly build web applications - Based on the Electron framework (
https://electronjs.org/
), you can build cross-platform desktop applications - Based on the restify framework (
http://restify.com/
), you can quickly build API interface projects - Read, write and manipulate databases, create useful command line tools to assist front-end development, etc...
How to learn Node.js?
Node.js learning path:
JavaScript 基础语法
+ Node.js built-in API modules (fs, path, http, etc.) + third-party API modules (express, mysql, etc.)
After knowing how to learn, let's install Node.js. After installation, you can run JavaScript code in node.
First, open the official website of node: https://nodejs.org/zh-cn/
, we will enter this interface:
Then we click the LTS download and install button on the left. After downloading, we click to open the target file, and just keep going to next.切记默认路径最好不要改变。
Determine whether the installation of node.js is successful
We Windows + R
open cmd
the terminal, enter in it node –v
, and then execute the command. If the output is the version number of the node.js you installed, it means the installation is successful.
As shown below:
So how to execute JavaScript code in node:
Very simple, the fastest way is in the directory where our js is located, 摁着shift + 点击右键
, we can power shall 终端
see , open it, and then enter node + js的文件名称
to execute JavaScript code in node.
Finally, let's take a look at the common shortcut keys and commands in the terminal:
hot key:
- Use the ↑ key to quickly navigate to the last executed command
- Use the tab key to quickly complete the path
- Use the esc key to quickly clear the currently entered command
- Enter the cls command to clear the terminal
Order:
- You can enter the drive letter by adding a colon to the drive letter name (default: C drive) eg:
D:
you can enter the D drive cd 加文件路径
: You can enter the folder where this file is located.
Keep reviewing, keep being excellent, be practical and do things seriously; pay attention to Sanlian and keep updating~~~