Archive: 2022

0

Reference

The schema part of the associated code In the schema we care about two pieces of information: the type of the association id (type), and which collection the association is (ref). The association of

0

Error handling

Method 1: try catch wraps the async request 1234567891011async function addStudent(req, res){ const {firstName, lastName, email} = req.body; const student = new Student({

0

Project structure

Create a project First create the src folder in the project folder, then create the entry file index.js in it, then run npm init -y . Then install express, dotenv, cors, morgan, Mongoose packages. n

0

Mongoose

Mongoose Introduction Mongoose is a package that uses promises and async/await. Mongoose is an ORM (object relational mapper) or ODM (object data mapping), which is specific to Mongodb. It enca

0

Relationships

Association (similar to sql) In sql, the association may be 1-to-many, and the many parts may be 0, 1, and Many. The data in Mongodb is stored in the form of an array, so it may be 0 data, regardles

0

CORS

Interface cross domain problem There are two main solutions to solve the interface cross-domain problem: CORS (mainstream solution, recommended) JSONP (flawed solution, only supports GET requests)

0

Interface (Summary)

Create interface steps (summarize previous lessons) Create the basic server: app.js 123456const express = require('express')const app = express()//main codeapp.listen(80, function(){

0

Middleware classification

Classification of middleware Express officially divides common middleware usage into five categories: Application-level middleware Route-level middleware Error-level middleware Express built-in

0

Middleware

The concept of middleware Middleware refers specifically to the intermediate processing links of business processes. The calling process of Express middleware is that when a request arrives at the E

0

Route

Route Concept Routing is a mapping relationship. In Express, routing refers to the mapping between client requests and server processing functions. The route in Express consists of three parts, whic