The use of ts-node of vue3.0
Prerequisites to prepare to download (in the TsNode file)
- download:
- effect:
- Use ts-node to run ts projects directly
- Initialize package.json
- node's life file
- Install express middleware
- 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");
})
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