https://github.com/bergos/nodeify-fetch
Node streams for fetch
https://github.com/bergos/nodeify-fetch
Last synced: 4 months ago
JSON representation
Node streams for fetch
- Host: GitHub
- URL: https://github.com/bergos/nodeify-fetch
- Owner: bergos
- License: mit
- Created: 2016-08-19T09:24:30.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-04-04T06:41:19.000Z (8 months ago)
- Last Synced: 2025-06-30T19:19:30.694Z (5 months ago)
- Language: JavaScript
- Size: 175 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nodeify-fetch
[](https://github.com/bergos/nodeify-fetch/actions/workflows/test.yaml)
[](https://www.npmjs.com/package/nodeify-fetch)
The `nodeify-fetch` package provides a Node.js [Readable](https://nodejs.org/api/stream.html#stream_class_stream_readable) stream interface for [fetch](https://fetch.spec.whatwg.org/).
In the browser, the built-in fetch is used.
In a Node.js environment, `node-fetch` it's used.
Since version 3.0, this packages is [ESM](https://nodejs.org/api/esm.html) only.
Check version 2.x if you are looking for a CommonJS package.
## Usage
The only difference to the fetch standard is the `.body` property.
`nodeify-fetch` patches the `.body` to a readable stream:
```javascript
import { promisify } from 'util'
import fetch from 'nodeify-fetch'
import { finished } from 'readable-stream'
async function main () {
const res = await fetch('http://worldtimeapi.org/api/timezone/etc/UTC')
if (!res.ok) {
console.log(`error ${res.statusText}(${res.status})`)
}
res.body.on('data', chunk => console.log(chunk.toString()))
await promisify(finished)(res.body)
}
main()
```