node-fetch only returning promise pending

前端 未结 3 1948
终归单人心
终归单人心 2021-02-13 11:04

I am trying out node-fetch and the only result I am getting is:

Promise { }

How can I fix this so I get a completed

3条回答
  •  醉梦人生
    2021-02-13 11:24

    u.json() returns a promise, so you'd need to do this

    nf(url)
    .then(function(u){ 
        return u.json();
    })
    .then(function(j) { 
        console.log(j); 
    });
    

    or as you're using node

    nf(url).then(u => u.json()).then(j => console.log(j));
    

提交回复
热议问题