伙計們.....
所以我想從第三方 api 獲取資料,但問題是資料被獲取但它沒有顯示在控制臺中.....意味著當我運行我的服務器時,資料會顯示在終端上但它沒有顯示在控制臺中,而不是本地主機繼續加載并且沒有顯示任何內容......
這是代碼...
const express = require('express')
const axios = require('axios')
const app = express()
const axiosInstance = axios.create({
baseURL: 'https://api.bittrex.com/api/v1.1/public',
header: { 'Access-Control-Allow_Origin': '*' }
})
app.get('/', async(req, res, next) => {
const response = await axiosInstance.get('/getmarketsummaries')
console.log(response.data.result)
})
app.listen(3000, () => {
console.log('listening on port 3000')
})
對此的任何解決方案如何在控制臺中顯示資料并停止 * localhost連續加載....
uj5u.com熱心網友回復:
您需要使用send方法發送回應,或者您可以使用json方法
app.get("/", async (req, res, next) => {
try {
const response = await axiosInstance.get("/getmarketsummaries");
console.log(response.data.result);
//You need To send data from using send method
res.status(200).send(response.data.result);
//Or you can use json method to send the data
res.status(200).json(response.data.result);
} catch (err) {
res.status(400).send(err);
}
});
uj5u.com熱心網友回復:
在 express 服務器中快速加載和掛起是因為您應該在 express get 呼叫中呼叫 next()
app.get('/', async(req, res, next) => {
const response = await axiosInstance.get('/getmarketsummaries')
console.log(response.data.result)
next()
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/419531.html
標籤:
