{"id":47623,"library":"fetch-ndjson","title":"fetch-ndjson","description":"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.","status":"active","version":"1.2.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install fetch-ndjson","lang":"bash","label":"npm"},{"cmd":"yarn add fetch-ndjson","lang":"bash","label":"yarn"},{"cmd":"pnpm add fetch-ndjson","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export only; named import will fail.","wrong":"import { ndjson } from 'fetch-ndjson'","symbol":"ndjson","correct":"import ndjson from 'fetch-ndjson'"},{"note":"CJS users must require the default property; breaking in v2+.","wrong":"const ndjson = require('fetch-ndjson')","symbol":"ndjson","correct":"const ndjson = require('fetch-ndjson').default"},{"note":"Namespace import not supported.","wrong":"import * as ndjson from 'fetch-ndjson'","symbol":"ndjson","correct":"import ndjson from 'fetch-ndjson'"}],"quickstart":{"code":"import ndjson from 'fetch-ndjson';\n\nasync function run() {\n  const response = await fetch('https://example.com/stream');\n  const reader = response.body.getReader();\n  const gen = ndjson(reader);\n  for await (const value of gen) {\n    console.log('Parsed object:', value);\n  }\n}\nrun().catch(console.error);","lang":"typescript","description":"Demonstrates consuming an NDJSON stream using fetch, getReader, and an async generator with for-await-of loop."},"warnings":[{"fix":"Update to use async generator syntax: for await (const val of ndjson(reader))","message":"In v1.0.0, ndjson returned an iterator directly; in v2.0.0 it returns an async generator. Code using for-await-of remains compatible, but manual .next() calls may break if not updated.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always call .getReader() on the readable stream before passing to ndjson.","message":"ndjson expects a ReadableStreamDefaultReader, not the stream itself. Passing response.body instead of response.body.getReader() will throw a TypeError.","severity":"gotcha","affected_versions":"*"},{"fix":"Use try/finally or AbortController to cancel the reader.","message":"The generator does not automatically close the reader when the stream ends or an error occurs; you must handle cancellation manually.","severity":"gotcha","affected_versions":"*"},{"fix":"Use node-fetch (v3) or undici with fetch polyfill, and ensure ReadableStream is available.","message":"Node.js <18 may not have global fetch or ReadableStream; polyfills required.","severity":"deprecated","affected_versions":"*"}],"env_vars":null,"search_vec":"'api':24,47 'async':26 'backpressur':37 'browser':62 'convert':13 'delimit':16 'design':40 'fetch':2,5,23,68 'fetch-ndjson':1,4 'focus':54 'generat':27 'global':67 'handl':33 'heavier':50 'incomplet':34 'javascript':77 'json':17,30 'librari':11 'lightweight':10 'line':35 'low':72 'mainten':73 'ndjson':3,6,18,57 'newlin':15 'newline-delimit':14 'node':64 'object':31 'pars':29 'parser':52 'readablestream':48 'recent':75 'respons':20 'ship':69 'sole':55 'stream':19,46,51 'type':71 'typescript':70,78 'unlik':49 'updat':76 'use':42 'v1.2.0':7 'v18':65 'web':45 'work':59 'yield':28","created_at":"2026-06-07T16:52:27.581336+00:00","updated_at":"2026-06-07T16:52:27.581336+00:00","problems":[{"fix":"Use `import ndjson from 'fetch-ndjson'` or `const ndjson = require('fetch-ndjson').default`.","cause":"Using named import instead of default import, or wrong CJS import syntax.","error":"TypeError: ndjson is not a function"},{"fix":"Ensure the fetch request returns a streaming response, or check response.ok.","cause":"Passing response.body (undefined) because fetch response is not a stream.","error":"TypeError: Cannot read properties of undefined (reading 'getReader')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"fetch-ndjson","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}