Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch and post text in NodeJS

I'm trying to grab text from an API that only returns a string of text ((here)) and having troubles throwing that out in a response. When posting, it comes out as [object Response], and the console.log doesn't show the text I want out of it.

The code I'm using:

fetch('http://taskinoz.com/gdq/api').then(
    function(response) {
      console.log(response);
      throttledSendMessage(channel, response);
      return response;
    })
  .catch(function(error) {
    throttledSendMessage(channel, "An error has occured");
  })

Log can be found here

like image 392
Riekelt Avatar asked Jun 21 '26 10:06

Riekelt


1 Answers

I think that because fetch returns a Response you need to call one of the functions on Response in order to get at the body's text. Here's an example:

fetch('https://github.com/')
  .then(res => res.text())
  .then(body => console.log(body));
like image 163
Aaron Avatar answered Jun 23 '26 23:06

Aaron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!