当前位置:网站首页>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)
})
边栏推荐
- 1-11 创建线上文件服务
- The 16th Heilongjiang Provincial Collegiate Programming Contest
- 双立体柱状图/双y轴
- Adobe Photoshop (PS) - script development - remove file bloated script
- 数字货币:影响深远的创新
- CA I ah, several times Oh, ah, a sentence IU home Oh
- Upgrade Kube with unknown flag: --network plugin
- 興奮神經遞質——穀氨酸與大腦健康
- Personal developed penetration testing tool Satania
- Double solid histogram / double y-axis
猜你喜欢

网络营销之四大误解

ICML2022 | 序列决策的效用理论

全面认识痛风:症状、风险因素、发病机理及管理

Four Misunderstandings of Internet Marketing

Et la dégradation du modèle de génération de texte? Simctg vous donne la réponse

文本生成模型退化怎麼辦?SimCTG 告訴你答案

根据肠道微生物组重新思考健康饮食

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

Adobe Photoshop (PS) - script development - remove file bloated script

qsort函数和模拟实现qsort函数
随机推荐
Analysis and proposal on the "sour Fox" vulnerability attack weapon platform of the US National Security Agency
The 16th Heilongjiang Provincial Collegiate Programming Contest
Electronic scheme development - Intelligent rope skipping scheme
笔记【JUC包以及Future介绍】
12345
Internet of things botnet gafgyt family and backdoor vulnerability exploitation of Internet of things devices
Is it safe to open an account for stock trading on mobile phones?
clickhouse原生監控項,系統錶描述
SQL server extracts pure numbers from strings
等级测评是什么意思?工作流程包含哪些?
Learning summary
What happens when word encounters an error while trying to open a file?
Et la dégradation du modèle de génération de texte? Simctg vous donne la réponse
CA I ah, how many times Oh, ah sentence IU home Oh 11111
twelve thousand three hundred and forty-five
Five years after graduation, I wondered if I would still be so anxious if I hadn't taken the test
两个skyline
The 16th Heilongjiang Provincial Collegiate Programming Contest
Side sleep ha ha ha
Icml2022 | utility theory of sequential decision making