打卡node day04--express-get.post.路由

1.基本使用

 npm i express

2.请求

get:

 

 

 post: express 不能直接解析请求体,所以需要第三方插件 ----》body-parser

 

 

  使用

npm install body-parser

const express = require('express')
const bodyParser = require('body-parser')
 
var app = express()

//app.use 使用 中间件

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
 
// parse application/json
app.use(bodyParser.json())

 

 

3.中间件

全局中间件

 

 

局部中间件 app.get('/pathname',fun1,fun2)

 

 

4.静态资源

 

 

 

5.路由(路由分层)

1) user 路由模块

 

 

2) 

 

posted @ 2020-03-18 14:52  学习。。。  阅读(132)  评论(0)    收藏  举报