There is a difference between the javascript implementation of fetch
and the one of node node-fetch
.
You can try the following:
const fetch = require('node-fetch');
fetch(url)
.then(response => response.body)
.then(res => res.on('readable', () => {
let chunk;
while (null !== (chunk = res.read())) {
console.log(chunk.toString());
}
}))
.catch(err => console.log(err));
The body returns a Node native readable stream, which you can read using the conveniently named read()
method.
You can find more about the differences under here. More specifically:
For convenience, res.body
is a Node.js
Readable stream, so decoding can be handled independently.
Hope it helps !