Related recommendations: "nodejs Tutorial"
HTTP transaction:
First of all, the HTTP transaction must be described completely The process from request to response:
- When a user initiates a request, domain name resolution is first performed
- to obtain the IP corresponding to the domain name After the address, establish a communication connection with the server through the TCP protocol. (Three-way handshake, establishing connection)
- After the service receives the user request, it performs business processing, and then returns the result after the request to the browser
- The browser receives the background data (4 times Waving hands, disconnecting) Note: connection:keep-alive always connected
Node modular specification:
Problems solved:
- Variable pollution : It means that the variables in the two JS files can access each other, resulting in variable coverage
- Dependency management: It requires manual management and is cumbersome and inefficient
- The runtime of node javascript`: that is The running environment is divided into two types (browser, Node)
node standard:
Each JS file is a module and has an independent scope
Through require("path" ) to introduce module.exports={things to be exposed}
to expose the collective nameInterface
npm package management tool (Node Package Manage)
1. Modify Taobao source: open the command control character and copy npm
config set registry https://registry.npm.taobao.org
2. Create a project directory (Folder) myapp
, and enter the terminal
3. Terminal project initialization: npx
express-generator
4. Terminal installation dependencies:npm
install
5. Start the terminal npm
start
6. Use the browser to access http://localhost:3000, and check that the access page pops up as success!
Browser modularization specification:
JS introduction specification:
Expose a single: export and the method to be exposed;
##Single introduction: import{Exposed method}from"
path.js";
Batch exposure: export default {Method to be exposed 1, Method to be exposed 2} ;
Batch import: import any value received from "
path.js";
Introduced two methods add, add1 and passed parameters
Note: When the introduced method has the same name as its own method, you can use xx as xx to get an alias
For more programming-related knowledge, please visit:
Programming Teaching! !
The above is the detailed content of Understand HTTP transactions and Node modular specifications. For more information, please follow other related articles on the PHP Chinese website!