当前位置:网站首页>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)
})
边栏推荐
猜你喜欢
兴奋神经递质——谷氨酸与大脑健康
《ClickHouse原理解析与应用实践》读书笔记(2)
本地浏览器打开远程服务器上的Jupyter Notebook/Lab以及常见问题&设置
介绍一款|用于多组学整合和网络可视化分析的在线平台
Icml2022 | utility theory of sequential decision making
Reading notes of Clickhouse principle analysis and Application Practice (3)
jupyter notebook/lab 切换conda环境
[untitled]
MySQL advanced 3
Adobe-Photoshop(PS)-脚本开发-去除文件臃肿脚本
随机推荐
ceshi deces
Zaah Sultan looks at the old driver
升级kube出现unknown flag: --network-plugin
Introduction of 3D Max fine model obj model into ArcGIS pro (II) key points supplement
给苏丹国安德森苏丹的撒过 d s g
ICLR'22 Spotlight | 怎样度量神经网络权重中的信息量?
A small step in code change and a big leap in thinking
qsort函数和模拟实现qsort函数
It is urgent for enterprises to protect API security
开发属于自己的包
Internet of things botnet gafgyt family and backdoor vulnerability exploitation of Internet of things devices
3Ds Max 精模obj模型导入ArcGIS Pro (二)要点补充
1-2 安装并配置MySQL相关的软件
申请Vector 总线协议彩图壁纸挂画,非常棒哦!
1-7 Path路径模块
Neurotransmetteurs excitateurs - glutamate et santé cérébrale
clickhouse原生监控项,系统表描述
ssh 默认端口不是22时的一些问题
1-13 express监听GET和POST请求&处理请求
go搭建服务器基础