【发布时间】:2019-07-14 05:43:15
【问题描述】:
我目前正在尝试通过我的 newsapi.org 调用传递 JSON 结果。但是我不知道该怎么做?任何帮助都会很棒!谢谢
newsapi.v2.topHeadlines({
category: 'general',
language: 'en',
country: 'au'
}).then(response => {
//console.log(response);
const respo = response;
});
app.get('/', function (req, res){
res.send(respo);
});
【问题讨论】:
-
您收到的错误是什么?你启动你的节点服务器了吗?它在哪个端口上运行?在浏览器中输入
localhost:<port number>会发生什么? -
当您访问
index route: /时会得到什么。您一定会收到TypeError: respo is not defined的错误。该 newsapi 调用必须在app.get("/")调用内,因为这是异步的。您的问题不完整,请确保您向我们提供了一个最小可重复的示例stackoverflow.com/help/minimal-reproducible-example
标签: javascript node.js express localhost