JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 25533
  • Score
    100M100P100Q147989F
  • License MIT

Node streams for fetch

Package Exports

  • nodeify-fetch
  • nodeify-fetch/browser.js
  • nodeify-fetch/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nodeify-fetch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

nodeify-fetch

build status npm version

The nodeify-fetch package provides a Node.js Readable stream interface for fetch. 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 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:

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()