当前位置:网站首页>1-18 创建最基本的express服务器&创建路由的API模块
1-18 创建最基本的express服务器&创建路由的API模块
2022-06-30 21:26:00 【画不完的饼】
创建最基本的express服务器
router.js
创建get接口
//导入express
const express = require('express')
//创建路由对象
const apirouter = express.Router()
apirouter.get('/get',(req,res)=>{
const query = req.query
res.send({
status:0, //0表示处理成功,1表示处理失败
msg:'GET请求成功',//状态描述
data:query //需要响应给客户端的数据
})
})
apirouter.post('/post',(req,res)=>{
const body = req.body
res.send({
status:0, //0表示处理成功,1表示处理失败
msg:'POST请求成功',//状态描述
data:body //需要响应给客户端的数据
})
})
//向外导出路由对象
module.exports=apirouter
server.js
//创建基本的web服务器
const express =require('express')
const app = express()
//POST接口需要配置表单解析中间件来解析客户端传递过来的数据
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')
})
边栏推荐
- Open source internship experience sharing: openeuler software package reinforcement test
- Icml2022 | utility theory of sequential decision making
- 利用日志服务器输出各种apache的日志的TOPN
- The 16th Heilongjiang Provincial Collegiate Programming Contest
- Three techniques for reducing debugging time of embedded software
- Adobe Photoshop (PS) - script development - remove file bloated script
- Sqlserver gets the data of numbers, Chinese and characters in the string
- clickhouse原生監控項,系統錶描述
- sdfsdf
- vim 常用快捷键
猜你喜欢

Software engineering UML drawing
![[untitled]](/img/42/47a8c8faaed33a1d9e864cb2ef7b72.png)
[untitled]

Prediction and regression of stacking integrated model

Text recognition svtr paper interpretation

How to move forward when facing confusion in scientific research? How to give full play to women's advantages in scientific research?

SQL server extracts pure numbers from strings

What about degradation of text generation model? Simctg tells you the answer

Markdown笔记简明教程

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

SQL Server 提取字符串中的纯数字
随机推荐
Software engineering UML drawing
漫谈Clickhouse Join
【等级测评师】等级测评师怎么报名?多少分及格?
《ClickHouse原理解析与应用实践》读书笔记(1)
个人开发的渗透测试工具Satania
Go build server Foundation
防范未授权访问攻击的十项安全措施
ArcGIS construction and release of simple road network data service and rest call test
双立体柱状图/双y轴
两个skyline
Reading notes of Clickhouse principle analysis and Application Practice (1)
银行集体下架的智能投顾产品,为何成了“鸡肋”?
本地浏览器打开远程服务器上的Jupyter Notebook/Lab以及常见问题&设置
利用日志服务器输出各种apache的日志的TOPN
《ClickHouse原理解析与应用实践》读书笔记(2)
Two skylines
Dm8: generate DM AWR Report
测试媒资缓存问题
【无标题】第一次参加csdn活动
How to run jenkins build, in multiple servers with ssh-key