fetch-ndjson (v1.2.0) is a lightweight library that converts newline-delimited JSON (NDJSON) streaming responses from the Fetch API into async generators yielding parsed JSON objects. It handles incomplete lines and backpressure, and is designed for use with the Web Streams API (ReadableStream). Unlike heavier streaming parsers, it focuses solely on NDJSON and works in both browser and Node (v18+ with global fetch). Ships TypeScript types. Low maintenance; no recent updates.
npm install fetch-ndjsonNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates consuming an NDJSON stream using fetch, getReader, and an async generator with for-await-of loop.
Update to use async generator syntax: for await (const val of ndjson(reader))
Always call .getReader() on the readable stream before passing to ndjson.
Use try/finally or AbortController to cancel the reader.
Use node-fetch (v3) or undici with fetch polyfill, and ensure ReadableStream is available.
Use `import ndjson from 'fetch-ndjson'` or `const ndjson = require('fetch-ndjson').default`.Ensure the fetch request returns a streaming response, or check response.ok.
No dependency data recorded yet.