当前位置:网站首页>1-18 create the most basic express server & API module for creating routes
1-18 create the most basic express server & API module for creating routes
2022-06-30 21:30:00 【Endless pie】
Create the most basic express The server
router.js
establish get Interface
// Import express
const express = require('express')
// Create routing objects
const apirouter = express.Router()
apirouter.get('/get',(req,res)=>{
const query = req.query
res.send({
status:0, //0 Indicates successful processing ,1 Indicates that the processing failed
msg:'GET The request is successful ',// State description
data:query // Data that needs to be responded to the client
})
})
apirouter.post('/post',(req,res)=>{
const body = req.body
res.send({
status:0, //0 Indicates successful processing ,1 Indicates that the processing failed
msg:'POST The request is successful ',// State description
data:body // Data that needs to be responded to the client
})
})
// Export routing objects out
module.exports=apirouter
server.js
// Create basic web The server
const express =require('express')
const app = express()
//POST The interface needs to configure the form parsing middleware to parse the data passed by the client
app.use(express.urlencoded({extends:false}))
const router = require('./apirouter')
app.use('/api',router)
app.listen(80,()=>{
console.log('express server running at http://127.0.0.1')
})
边栏推荐
- 1-20 预检请求
- ca i啊几次哦啊句iu家哦11111
- Go build server Foundation
- Adobe Photoshop (PS) - script development - remove file bloated script
- ICLR'22 Spotlight | 怎样度量神经网络权重中的信息量?
- Is it safe to open an account for stock trading on mobile phones?
- 根据肠道微生物组重新思考健康饮食
- Oracle 数据库表结构 Excel 导出
- 《ClickHouse原理解析与应用实践》读书笔记(1)
- .netcore redis GEO类型
猜你喜欢

Multi table operation - foreign key constraint

Five years after graduation, I wondered if I would still be so anxious if I hadn't taken the test

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

ICLR'22 Spotlight | 怎样度量神经网络权重中的信息量?

布隆过滤器

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

《ClickHouse原理解析与应用实践》读书笔记(3)

Open source internship experience sharing: openeuler software package reinforcement test

Clickhouse native monitoring item, system table description

多态在代码中的体现
随机推荐
Zaah Sultan looks at the old driver
USBCAN分析仪的配套CAN和CANFD综合测试软件LKMaster软件解决工程师CAN总线测试难题
It is urgent for enterprises to protect API security
What happens when word encounters an error while trying to open a file?
Ssh server configuration file parameter permitrootlogin introduction
漫谈Clickhouse Join
[untitled]
攻防演练中的防泄露全家福
1-12 preliminary understanding of Express
测试勋章1234
What about degradation of text generation model? Simctg tells you the answer
asp. Net core JWT delivery
Two skylines
sdfsdf
ArcGIS construction and release of simple road network data service and rest call test
SQL server extracts pure numbers from strings
Metauniverse may become a new direction of Internet development
mysql-批量更新
Adobe Photoshop (PS) - script development - remove file bloated script
ca i啊几次哦啊句iu家哦11111