Back-end common sense that should be understood as a front-end

1. Front-end interview question bank ( necessary for interview) recommendation: ★★★★★            

Address: front-end interview question bank

What is a server

  • server, also known as backend, server
  • The front end is the visible and operable part of the user, such as branches and leaves
  • The server provides "support" and "nutrition" for the front end, such as tree roots

what is the front end

  • Narrow sense: web page
  • Broad sense: various clients, such as App, PC client, etc.

Responsibilities of the server

  • Provide the data to be displayed on the front end
  • Receive the data to be submitted by the front end
  • Store data (software companies value data very much and collect all kinds of data)

server-side representation

  • The front-end ajax needs to call an interface, such as using the get request to obtain data, and the post request to submit data
  • This interface is provided by the server

Front-end and back-end interactive communication - HTTP protocol

  • Hypertext Transfer ProtocolHyper Text Transfer Protocol
  • Specifies how the client and server communicate
  • It is the standard and cornerstone of data communication in the Internet world

HTTP - Generic

  • url: the address of the back-end interface, that is, the address of the front-end Ajax request
  • method: request method, such as GET POST PUT DELETE etc.
  • Status code: the status returned by the interface, such as 200 302 404 500, etc.

HTTP - Request

  • Request: request, the front end sends to the server
    • Request Body: The request is the data sent to the backend
    • Request Content-type: the format of sending data, such as JSON format
    • ...

HTTP - Response

  • Response: return/response, the server returns to the front end
    • Response Body: the data returned from the backend to the frontend
    • Response Content-type: the format of the returned data, such as JSON format

Demonstrate a Get request


Demonstrate a POST request


A web page may correspond to multiple servers

The resources that a web page needs to load may have

  • html
  • css
  • js
  • picture
  • audio and video
  • business data

Different resources may come from different domain names

  • html may come from a separate domain name
  • js css may come from a separate domain name
  • Data may come from a separate domain name
  • Different domain names can correspond to different servers

The server can also be divided into static services (processing html css js images, etc.) and data services (providing data interfaces)


How the server processes and returns data

  • Define url rules for front-end requests - routing (url is required for front-end Ajax requests)
  • Request to get data, use Response to return data
    • Also referred to simply as req and res
    • Obtainable through Request: method url body
    • Via Response: Can be set: status code, Content-type, body
  • Read and store data - database
    • Database, dedicated to data storage and query
    • The database is an independent system, not exclusive to nodejs
    • Basic operations: query, add, delete, modify, sort, etc. all require query conditions


What is a router

  • Server-side entry rules
  • Need to agree with the front end
  • Just like the ancient city gates, the city gates have specific entrances to enter, and each entrance has a specific function
  • Backend defines GET /api/list route => frontend axios.get( /api/list' )
  • Backend definition POST /api/create route => frontend axios.post( '/api/creaate' , {..)
  • Routing defines the sending rules, and url is the specific sending form

what does the route contain

  • Define method, such as GET/POST, etc.
  • Define url rules like /api/list and /api/create
  • Define input (Request body) and output (Response body) formats

Configure the Nodejs environment

Enter Node official website to install:

After the installation is complete, use the following command to check whether the installation is complete:

  • node -v
  • npm -v

Continue to install the nrm management package source:

  • npm i nrm -g
  • nrm ls
  • nrm use taobao

Use nvm to manage multiple versions of nodejs

  • Mac OS, usebrew install nvm
  • windows, search in github nvm-windows, there is a download address

use nvm

  • nvm listView all current node versions
  • nvm install v16.10.0Install the specified version
  • nvm use —delete-prefix 16.10.0Switch to the specified version

The difference between Nodejs and Javascript

Javascript

  • Use ECMAScript syntax specification, plus Web API (DOM operation, BOM operation, Ajax), all are indispensable

  • Combining the two, you can complete any operation on the browser side

  • ECMAScript defines syntax (variable definition, loop, judgment, function, prototype and prototype chain, scope and closure, asynchronous, etc.), writing javascript and nodejs must be followed

Nodejs

  • Use ECMAScript syntax specification, plus nodejs API, both are indispensable
  • Handle http, handle files, etc. For details, refer to: nodejs.cn/api-v16/
  • Combining the two, you can complete any operation on the server side

CommonJs

  • In the Nodejs environment, the module system is supported by default, and the module system follows the CommonJS specification
  • A js file in Nodejs is a module
// index.js
function add(a, b) {
  return a + b;
}

function minus(a, b) {
  return a - b;
}

// 导出单个
module.exports = add;
// 在别的文件引入
// const add = require("index.js");

// 导出多个
module.exports = {
  add,
  minus
};
// 在别的文件引入
// const { add, minus } = require("index.js");

// 直接引入npm包
// const _ = require("lodash");

debugging

  1. Use the breakpoint debugging that comes with vscode
  2. Package.json --inspect=9229starts the program after adding parameters, enter the URL: chrome://inspect, and select the corresponding program debugger

The difference between backend development and frontend development

service stability

  • The server side may be subject to various malicious attacks and misoperations

  • A single client can hang up unexpectedly, but the server cannot

Consider CPU and memory (optimization, scaling)

  • The client monopolizes a browser, memory and CPU are not a problem
  • The server side has to carry a lot of requests, CPU and memory are scarce resources

logging

  • The front end will also participate in writing logs, but it is only the initiator of the logs and does not care about the follow-up
  • The server side needs to record logs, store logs, and analyze logs, and the front end does not care

Safety

  • The server side must be ready to receive various malicious attacks at any time, and the front end is much less
  • Such as: unauthorized operation, database attack, etc.

Cluster and service split

  • Product development is fast and traffic can increase rapidly
  • How to carry large traffic by scaling machines and splitting services?

1. Front-end interview question bank ( necessary for interview) recommendation: ★★★★★            

Address: front-end interview question bank

Guess you like

Origin blog.csdn.net/weixin_42981560/article/details/131945234