A backend interface service since vue3.0

The use of ts-node of vue3.0

Prerequisites to prepare to download (in the TsNode file)

  • download:
    • yarn add ts-node -g
  • effect:
    • Use ts-node to run ts projects directly
  • Initialize package.json
    • npm init -y
  • node's life file
    • yarn add @types/node -D
  • Install express middleware
    • yarn add express -S
  • Install express life files
    • yarn add @types/express -D
  • Install:yarn add axios -S
  • Install:yarn add typescript -g

Simply open a background service index.ts

import express,{
    
    Express,Router,Request,Response} from "express"
import axios from "axios"

const app:Express = express()
const router:Router = express.Router() // 分模块

app.use("/api",router) // 

router.get('/list',async (req:Request,res:Response)=>{
    
    
 const result = await axios.post('https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=statisGradeCityDetail,diseaseh5Shelf')
 console.log("result",result);
 res.json({
    
    
   data:result.data 
 })
})

app.listen(9999,()=>{
    
    
  console.log("success server http://localhost:9999");
  
}) // 开一个服务 端口为3333

After installing the above things, configure the script instructions

  • “dev”: “ts-node index.ts”,
  • Runtime:yarn dev
{
    
    
  "dependencies": {
    
    
    "axios": "^0.26.1",
    "express": "^4.17.3",
    "ts-node": "^10.7.0",
    "typescript": "^4.6.2"
  },
  "name": "TsNode",
  "version": "1.0.0",
  "main": "index.js",
  "devDependencies": {
    
    
    "@types/express": "^4.17.13",
    "@types/node": "^17.0.21"
  },
  "scripts": {
    
    
    "dev": "ts-node index.ts",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": ""
}

  • The effect after running
    • success server http://localhost:9999

Check the backend interface

  • use postman to verify
    insert image description here

Guess you like

Origin blog.csdn.net/weixin_43845137/article/details/123645711