In the world of JavaScript, there exists a distinction between the implementation of fetch
and that of node-fetch
.
If you're interested in exploring this difference, you can experiment with the following code snippet:
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 usage of res.body
provides access to a Node native readable stream, allowing for data extraction through the use of the handy read()
method.
To delve deeper into these distinctions, check out this link. Specifically, it sheds light on how res.body
functions as a Node.js
Readable stream for independent decoding purposes.
May this information prove useful to you!