Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bergos/nodeify-fetch
Node streams for fetch
https://github.com/bergos/nodeify-fetch
Last synced: about 2 months ago
JSON representation
Node streams for fetch
- Host: GitHub
- URL: https://github.com/bergos/nodeify-fetch
- Owner: bergos
- Created: 2016-08-19T09:24:30.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-10-02T15:30:44.000Z (over 2 years ago)
- Last Synced: 2024-04-26T22:03:19.300Z (9 months ago)
- Language: JavaScript
- Size: 161 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nodeify-fetch
[![build status](https://img.shields.io/github/workflow/status/bergos/nodeify-fetch/Test)](https://github.com/bergos/nodeify-fetch/actions/workflows/test.yaml)
[![npm version](https://img.shields.io/npm/v/nodeify-fetch.svg)](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()
```