response-iterator is a utility library designed to normalize various HTTP response bodies into a consistent asynchronous iterator interface, compatible across both browser and Node.js environments. It currently stands at stable version 1.0.10 and is regularly maintained. The library abstracts away the differences in how `Response` objects (or similar constructs) are handled by different HTTP clients such as standard `fetch`, `node-fetch`, `cross-fetch`, `axios`, `got`, and `undici`. Its key differentiator is providing a simple `for await...of` loop mechanism to consume streamed data chunks, making it easier to process large responses efficiently without loading the entire body into memory, irrespective of the underlying fetch implementation. It significantly simplifies working with streaming data by adhering to the `Symbol.asyncIterator` protocol.
npm install response-iteratorVerified import paths — ran on the pinned version, not inferred.
Demonstrates fetching a JSON file and consuming its content as an async iterator.
Consult the project's GitHub release history and examples. Re-evaluate direct usage of internal APIs or patterns that might have changed.
Migrate your consuming code to use ES Modules (`import responseIterator from 'response-iterator';`) or use dynamic `import()` within CommonJS. Ensure your Node.js environment or bundler is configured for ESM.
Ensure the function consuming the iterator is declared `async` and the iteration uses `for await (const chunk of iterator)`. Handle potential errors within the loop or with a `try...catch` block around the async operation.
Always wrap the `fetch` call and the `for await...of` loop in a `try...catch` block. Implement robust error handling for network issues, parsing errors, and any custom logic applied to chunks.
Change `const responseIterator = require('response-iterator');` to `import responseIterator from 'response-iterator';`. Ensure your project's `package.json` has `"type": "module"` or use dynamic imports like `const responseIterator = (await import('response-iterator')).default;`.Verify the import statement is `import responseIterator from 'response-iterator';` (for a default export). If in CommonJS, confirm dynamic import usage: `const responseIterator = (await import('response-iterator')).default;`.Ensure the function containing `for await (const chunk of responseIterator(res))` is declared `async`. Also, verify that `responseIterator(res)` is indeed returning an async iterable and not a plain value or a Promise of a value that needs further resolution.
No dependency data recorded yet.