为什么没有解决“承诺{<pending>}”?

on猫

我正在尝试从Storm Glass API中获取数据。我正在使用他们的模板获取请求(https://docs.stormglass.io/?javascript#point-request)。

当我运行脚本时,控制台会Promise { <pending> }无限期读出“ ”。因此,请求未返回值,但我无法弄清楚原因。有任何想法吗?

我已将我的API密钥替换为 <My API key>

const http = require('http')
const fetch = require('isomorphic-fetch');

http.createServer((req, res) => {

////////////////////////////////////////////////App code
const lat = 58.7984;
const lng = 17.8081;
const params = 'waveHeight,airTemperature';

fetch(`https://api.stormglass.io/point?lat=${lat}&lng=${lng}&params=${params}`, {
  headers: {
    'Authorization': '<My API key>'
  }
}).then(function(response) {
  // Do something with response data.
  const jsonData = response.json();
  console.log(jsonData)
});

/////////////////////////////////////////////////////////
}).listen(3000);

console.log("service running on http://localhost:3000");
格罗特罗

response.json函数返回一个Promise,而不是反序列化的对象。您的代码应为:

fetch(`https://api.stormglass.io/point?lat=${lat}&lng=${lng}&params=${params}`, {
  headers: {
    'Authorization': '<My API key>'
  }
})
.then(response => response.json())
.then(function(jsonData) {
  // Do something with response data
  console.log(jsonData)
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么这个承诺没有解决回给呼叫者?

为什么“getLayoutInflater()”没有解决

猫鼬承诺没有解决

为什么在使用 node 和 redis 时我的承诺没有解决?我的数组返回第一次迭代而不是等待整个代码运行

从.then()接收承诺{<pending>}

为什么我的代码没有解决求步数计算数的问题?

不明白为什么这种方法没有解决

GsonConverter没有解决

放心进口没有解决

为什么我的窗口滚动事件根本没有触发。其他答案没有解决

Axios 没有解决,状态仍然是一个承诺

异步等待返回承诺<pending>

接受承诺<Pending>而不是价值

承诺{<pending>}-尝试等待.map

等待的承诺仍然返回<pending>

没有错误,但 findviewbyid 没有解决

为什么我的函数返回 Promise { <pending> }

为什么Promise在.then之后返回为<Pending>?

Unity Project没有解决方案文件

Javascript:Promise.all似乎没有解决

Promise 没有解决这个问题

expressJS 路由问题,简单的东西没有解决

Celery任务状态仅为“ PENDING”和“ SUCCESS”。为什么任务状态中没有“ STARTED”?

GAE:<min-pending-latency>和<max-pending-latency>有什么区别?

为什么 Vuex 的 action 返回一个 promise<pending>?

为什么我的异步函数返回Promise {<pending>}而不是值?

为什么我的异步函数返回Promise {<pending>}而不是值?

node.js 函数返回 Promise { <pending> },为什么?

没有连接适配器;跳过布局没有解决方案工作