当前位置:网站首页>1-13 express listens to get and post requests & processes requests
1-13 express listens to get and post requests & processes requests
2022-06-30 21:30:00 【Endless pie】
express monitor GET request
// Import express
const express = require('express')
// establish web The server
const app = express()
// Listen to the client GET and POST request
//app.get Monitor client get request
app.get('/user',(req,res)=>{
// call express.send Method to the client corresponding object
res.send({name:'wang',gender:' male '})
})
//app.post Monitor client get request
app.post('/user',(req,res)=>{
// call express.send Method to the client corresponding object
res.send(' The request is successful ')
})
// start-up web The server
app.listen(80,()=>{
console.log('sever')
})
obtain URL Query parameters carried in
app.get('/',(req,res)=>{
// adopt req.query You can get the data sent by the client , Query parameters
// Be careful , By default req.query Is an empty object
console.log(req.query)
res.send(req.query)
})
obtain URL Dynamic parameters in
adopt req.params object . Access to URL in , adopt : Matching dynamic parameters
app.get('/user/:id',(req,res)=>{
//:id It's a dynamic parameter
//params The default is an empty object
// In it is stored through : Dynamically matched parameter values
let params = req.params
res.send(params)
})
边栏推荐
- Double solid histogram / double y-axis
- ICLR'22 Spotlight | 怎样度量神经网络权重中的信息量?
- Sqlserver string type converted to decimal or integer type
- 《ClickHouse原理解析与应用实践》读书笔记(2)
- 3Ds Max 精模obj模型导入ArcGIS Pro (二)要点补充
- To the Sultanate of Anderson
- Spatiotemporal data mining: an overview
- 1-18 创建最基本的express服务器&创建路由的API模块
- 1-21 JSONP接口
- 笔记【JUC包以及Future介绍】
猜你喜欢

MySQL advanced 3

Dm8: generate DM AWR Report

申请Vector 总线协议彩图壁纸挂画,非常棒哦!

Reading notes of Clickhouse principle analysis and Application Practice (2)

jupyterbook 清空控制台输出

文本生成模型退化怎么办?SimCTG 告诉你答案

興奮神經遞質——穀氨酸與大腦健康

Apply for vector bus protocol color picture wallpaper hanging picture, very good!

SQL server extracts pure numbers from strings

个人开发的渗透测试工具Satania
随机推荐
给苏丹国安德森苏丹的撒过 d s g
1-16 路由的概念
Why have the intelligent investment advisory products collectively taken off the shelves of banks become "chicken ribs"?
用yml文件进行conda迁移环境时的报错小结
Dm8: generate DM AWR Report
Phoenix architecture: an architect's perspective
Fletter nested hell? No, constraintlayout to save!
twelve thousand three hundred and forty-five
1-7 Path路径模块
Four Misunderstandings of Internet Marketing
物联网僵尸网络Gafgyt家族与物联网设备后门漏洞利用
Neurotransmetteurs excitateurs - glutamate et santé cérébrale
jupyterbook 清空控制台输出
How to run jenkins build, in multiple servers with ssh-key
sdfsdf
pytorch geometric torch-scatter和torch-sparse安装报错问题解决
Open source internship experience sharing: openeuler software package reinforcement test
Apply for vector bus protocol color picture wallpaper hanging picture, very good!
【无标题】
代码改变一小步,思维跨越一大步