【发布时间】:2020-05-24 14:08:40
【问题描述】:
我使用 API 来获取一些我需要的信息。
let bodyapi = await axios.get(`www.example.com`)
然后我像这样导出我需要的信息:
const number = bodyapi.data.slice(-11);
module.exports = number
然后我用const number = require('./myapp.js') 在我的实际文件上运行它(像往常一样)。
但问题是当我阅读它时,它返回[object Object]
const number = require('./myapp.js')
sleep(5000) // It's a timeout function I've set, ignore it, it's just so I don't run the code too fast since it uses API''
console.log("Your ID: " + number) //Here is where it reads as [object Object]
控制台结果:
Your ID: [object Object]
我的问题是:我该如何修复它,所以它会读取我需要它读取的内容? bodyapi 被制成一个“异步”函数。我使用Axios 读取api。
如果您需要更多信息,请在 cmets 中告诉我,以便我编辑这篇文章。感谢您的宝贵时间!
【问题讨论】:
-
在导出之前确保
console.log(number)看起来像你想要的那样。
标签: javascript node.js api axios export