{"library":"miniget","title":"miniget - Small HTTP(S) GET Client","description":"miniget is a lightweight HTTP(S) GET request library designed for both Node.js and browser environments, emphasizing minimal dependencies and a small footprint. It provides core functionalities like automatic redirects (up to 10 by default), request retries for 5xx or connection errors, and reconnects for interrupted downloads, allowing streams to resume. The current stable version is `4.2.3`, with releases typically addressing bug fixes and minor features rather than following a strict semantic versioning cadence between major versions. Key differentiators include its zero-dependency nature, support for streaming responses via a readable stream, and methods for concatenating responses into a single text body. It also exposes a configurable `defaultOptions` object for global settings and ships with TypeScript type definitions, making it well-suited for modern TypeScript projects.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install miniget"],"cli":null},"imports":["import miniget from 'miniget';","import { MinigetError } from 'miniget';","import { Defaults } from 'miniget';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import miniget from 'miniget';\nimport { createWriteStream } from 'node:fs';\n\nasync function fetchAndStreamData(url: string, filePath: string) {\n  try {\n    // Fetch and concatenate content as text\n    const textBody = await miniget(url).text();\n    console.log(`Fetched text from ${url.substring(0, 30)}... : ${textBody.substring(0, 50)}...`);\n\n    // Stream content to a file\n    const stream = miniget(url, { maxRedirects: 5, maxRetries: 1 });\n    stream.on('redirect', (newUrl) => console.log(`Redirected to: ${newUrl}`));\n    stream.on('error', (err) => console.error(`Stream error: ${err.message}`));\n    stream.on('response', (res) => console.log(`Received status: ${res.statusCode}`));\n\n    const fileStream = createWriteStream(filePath);\n    stream.pipe(fileStream);\n\n    await new Promise<void>((resolve, reject) => {\n      fileStream.on('finish', () => {\n        console.log(`Streamed content to ${filePath}`);\n        resolve();\n      });\n      fileStream.on('error', reject);\n    });\n\n  } catch (error: any) {\n    console.error(`Failed to fetch or stream: ${error.message}`);\n  }\n}\n\n// Example usage with a placeholder URL\n// Replace with a valid URL for actual execution\nconst exampleUrl = 'https://jsonplaceholder.typicode.com/posts/1';\nconst outputFilePath = './output.json';\nfetchAndStreamData(exampleUrl, outputFilePath);\n\n// You can also modify global defaults\nminiget.defaultOptions.headers = { 'User-Agent': 'miniget-example-app' };\nconsole.log('Global User-Agent set.');","lang":"typescript","description":"This quickstart demonstrates both promise-based text retrieval and streaming a response to a file using `miniget`, including error handling and event listeners for redirects and responses. It also shows how to configure global default options.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}