{"library":"pacote","title":"Pacote: JavaScript Package Downloader","description":"Pacote is a robust JavaScript library designed for programmatically fetching package manifests and tarballs, primarily from the npm registry but also supporting various other package specifiers like Git repositories, local directories, and tarball URLs. It is the underlying package fetching mechanism used by the npm CLI itself, ensuring high compatibility with npm's ecosystem. The current stable version is 21.5.0, released in March 2026, and the project demonstrates an active release cadence with frequent updates across major versions (e.g., v19, v20, v21 receiving simultaneous updates). Key differentiators include its ability to resolve any npm-compatible package specifier, simulate packument data for non-registry sources, and run `prepare` scripts for Git or directory-based packages to replicate the publishing process. It provides APIs for resolving package URLs, extracting contents to a directory, fetching manifests, and downloading tarball data as buffers or streams.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install pacote"],"cli":null},"imports":["import pacote from 'pacote';","const pacote = require('pacote');","import pacote from 'pacote';\nconst manifest = await pacote.manifest('foo@latest');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const pacote = require('pacote');\nconst path = require('path');\nconst fs = require('fs/promises');\n\nasync function main() {\n  const packageName = 'lodash';\n  const packageVersion = '4.17.21';\n  const gitSpec = 'github:npm/cli';\n  const tarballUrl = 'https://registry.npmjs.org/is-odd/-/is-odd-3.0.1.tgz';\n\n  console.log(`--- Fetching manifest for ${packageName}@${packageVersion} ---`);\n  try {\n    const manifest = await pacote.manifest(`${packageName}@${packageVersion}`);\n    console.log(`Got manifest for ${manifest.name}@${manifest.version}`);\n    console.log(`Dependencies: ${Object.keys(manifest.dependencies || {}).join(', ') || 'None'}`);\n  } catch (error) {\n    console.error(`Failed to fetch manifest: ${error.message}`);\n  }\n\n  console.log(`\\n--- Extracting ${gitSpec} to a temporary path ---`);\n  const tempExtractPath = path.join(__dirname, 'temp-extracted-repo');\n  try {\n    await fs.mkdir(tempExtractPath, { recursive: true });\n    const { from, resolved, integrity } = await pacote.extract(gitSpec, tempExtractPath);\n    console.log(`Extracted '${from}' (resolved to '${resolved}') with integrity '${integrity}' to '${tempExtractPath}'`);\n    const files = await fs.readdir(tempExtractPath);\n    console.log(`Extracted files (first 5): ${files.slice(0, 5).join(', ')}...`);\n  } catch (error) {\n    console.error(`Failed to extract package: ${error.message}`);\n  } finally {\n    await fs.rm(tempExtractPath, { recursive: true, force: true });\n  }\n\n  console.log(`\\n--- Downloading tarball from ${tarballUrl} ---`);\n  try {\n    const tarballData = await pacote.tarball(tarballUrl);\n    console.log(`Got ${tarballData.length} bytes of tarball data. Resolved URL: ${tarballData.resolved}`);\n  } catch (error) {\n    console.error(`Failed to download tarball: ${error.message}`);\n  }\n}\n\nmain().catch(console.error);","lang":"javascript","description":"Demonstrates fetching a package manifest, extracting a package from a Git repository, and downloading a tarball directly from a URL using `pacote`'s core asynchronous APIs.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}