{"library":"npm-registry-fetch","title":"npm Registry Fetch Client","description":"npm-registry-fetch is a Node.js library providing a fetch-like API for interacting with npm registry APIs. It abstracts away complexities like selecting the correct registry, handling package scopes, and managing authentication details based on standard npm configuration. This package is the modern successor to npm-registry-client. Its current stable version is 19.1.1, and it maintains a consistent, active release cadence with frequent patch and minor updates, and occasional major version bumps primarily for Node.js engine compatibility or internal API refinements. A key differentiator is its deep integration with npm's ecosystem, ensuring correct behavior for features like cache revalidation for write operations, which makes it an authoritative choice for programmatic interaction with the npm registry.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install npm-registry-fetch"],"cli":null},"imports":["import npmFetch from 'npm-registry-fetch';","import npmFetch from 'npm-registry-fetch'; await npmFetch.json('/-/ping');","import npmFetch from 'npm-registry-fetch'; npmFetch.json.stream('/-/all', 'rows.*.doc');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import npmFetch from 'npm-registry-fetch';\n\nasync function fetchPing() {\n  try {\n    // Basic fetch request to the npm registry ping endpoint\n    const res = await npmFetch('/-/ping', {\n      // Optional: Specify a custom registry, defaults to npmjs.org\n      // registry: 'https://registry.npmjs.org/',\n      // Optional: Pass an AbortSignal for request cancellation\n      // signal: AbortSignal.timeout(5000),\n      // Optional: Authentication token (e.g., from process.env)\n      // token: process.env.NPM_TOKEN ?? '',\n    });\n    console.log('Status:', res.status);\n    console.log('Headers:', res.headers.raw());\n    const data = await res.json(); // Standard Fetch API method to parse JSON body\n    console.log('Body (parsed JSON):', data);\n  } catch (error) {\n    console.error('Failed to fetch via raw response:', error.message);\n  }\n\n  try {\n    // Using the convenience method fetch.json for direct JSON parsing\n    const jsonBody = await npmFetch.json('/-/ping');\n    console.log('\\nUsing npmFetch.json for ping:', jsonBody);\n  } catch (error) {\n    console.error('Failed to fetch via .json helper:', error.message);\n  }\n}\n\nfetchPing();","lang":"typescript","description":"Demonstrates how to use `npm-registry-fetch` to make a basic GET request to the npm registry's ping endpoint, handling both raw `Response` objects and using the `fetch.json` utility for direct JSON parsing.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}