当前位置:网站首页>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')
})
边栏推荐
- 文本生成模型退化怎么办?SimCTG 告诉你答案
- Oracle 数据库表结构 Excel 导出
- How to run jenkins build, in multiple servers with ssh-key
- 数字货币:影响深远的创新
- 1-19 利用CORS解决接口跨域问题
- Who are you and I
- NCAT detailed introduction (Reprint)
- ArcGIS construction and release of simple road network data service and rest call test
- Fletter nested hell? No, constraintlayout to save!
- 介绍一款|用于多组学整合和网络可视化分析的在线平台
猜你喜欢

漫谈Clickhouse Join

Random talk about Clickhouse join

jenkins下载插件下载不了,解决办法

It is urgent for enterprises to protect API security

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

时空数据挖掘:综述

Ten security measures against unauthorized access attacks

Introduction of 3D Max fine model obj model into ArcGIS pro (II) key points supplement

Personal developed penetration testing tool Satania

Why have the intelligent investment advisory products collectively taken off the shelves of banks become "chicken ribs"?
随机推荐
How to run jenkins build, in multiple servers with ssh-key
Iclr'22 spotlight | how to measure the amount of information in neural network weights?
1-13 express监听GET和POST请求&处理请求
FreeRTOS record (IX. an example of a bare metal project transferring to FreeRTOS)
1-1 数据库的基本概念
数字货币:影响深远的创新
升级kube出现unknown flag: --network-plugin
的撒啊苏丹看老司机
1-18 创建最基本的express服务器&创建路由的API模块
Auto-created primary key used when not defining a primary key
Radar data processing technology
. NETCORE redis geo type
Oracle 数据库表结构 Excel 导出
1-14 express managed static resources
1-16 路由的概念
Nacos部署及使用
电子方案开发——智能跳绳方案
Is it safe to open an account for stock trading on mobile phones?
Can flinksql two Kafka streams join?
Clickhouse native monitoring item, system table description