当前位置:网站首页>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')
})
边栏推荐
- 做一个 Scrollbar 的思考
- Is it safe to open an account for stock trading on mobile phones?
- 元宇宙可能成为互联网发展的新方向
- 1-7 path module
- 1-7 Path路径模块
- Metauniverse may become a new direction of Internet development
- Who are you and I
- ArcGIS构建发布简单路网Network数据服务及Rest调用测试
- Internet of things botnet gafgyt family and backdoor vulnerability exploitation of Internet of things devices
- 攻防演练中的防泄露全家福
猜你喜欢
随机推荐
twelve thousand three hundred and forty-five
Four Misunderstandings of Internet Marketing
NCAT detailed introduction (Reprint)
ca i啊几次哦啊句iu家哦11111
Icml2022 | utility theory of sequential decision making
Fletter nested hell? No, constraintlayout to save!
时空数据挖掘:综述
Ten security measures against unauthorized access attacks
1-1 basic concepts of database
asp.net core JWT传递
文本生成模型退化怎么办?SimCTG 告诉你答案
1-2 install and configure MySQL related software
sdfsdf
针对美国国家安全局“酸狐狸”漏洞攻击武器平台的分析与应对方案建议
CA I ah, several times Oh, ah, a sentence IU home Oh
Clickhouse distributed table engine
Who are you and I
“信任机器”为发展赋能
Digital currency: far-reaching innovation
1-19 利用CORS解决接口跨域问题