Home >Web Front-end >JS Tutorial >Understand HTTP transactions and Node modular specifications

Understand HTTP transactions and Node modular specifications

青灯夜游
青灯夜游Original
2020-12-14 18:24:182380browse

Understand HTTP transactions and Node modular specifications

Related recommendations: "nodejs Tutorial"

HTTP transaction:

First of all, the HTTP transaction must be described completely The process from request to response:

Understand HTTP transactions and Node modular specifications

  1. When a user initiates a request, domain name resolution is first performed
  2. 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)
  3. After the service receives the user request, it performs business processing, and then returns the result after the request to the browser
  4. The browser receives the background data (4 times Waving hands, disconnecting) Note: connection:keep-alive always connected
Node modular specification:

Problems solved:

  1. Variable pollution : It means that the variables in the two JS files can access each other, resulting in variable coverage
  2. Dependency management: It requires manual management and is cumbersome and inefficient
  3. 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!

Understand HTTP transactions and Node modular specifications

Understand HTTP transactions and Node modular specifications

Browser modularization specification:

JS introduction specification:

Expose a single: export and the method to be exposed;

Understand HTTP transactions and Node modular specifications

##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";

Understand HTTP transactions and Node modular specifications

Understand HTTP transactions and Node modular specifications

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


Understand HTTP transactions and Node modular specifications

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn