@jayf0x/npm-exists
v2.1.2
Published
The fastest way to check if an npm package exists. Zero dependencies, lightweight, and uses ultra-fast HTTP HEAD requests.
Downloads
320
Maintainers
Readme
npm-exists
The simplest, fastest possible npm package existence check. One HEAD request, 0 deps
Install
npm install @jayf0x/npm-existsUsage
import npmExists from '@jayf0x/npm-exists'
await npmExists('react') // true
await npmExists('not-a-pkg42') // false// Custom registry
await npmExists('my-pkg', { registry: 'https://my.private.registry.io' })
// Suppress network errors
await npmExists('react', { silent: true })// Get the registry URL (useful with axios, ky, etc.)
import { getNpmUrl } from '@jayf0x/npm-exists'
getNpmUrl('react') // 'https://registry.npmjs.org/react'
getNpmUrl('@types/node') // 'https://registry.npmjs.org/%40types%2Fnode'CLI
npx @jayf0x/npm-exists react
# ✓ react exists on npm
npm-exists my-pkg
# ✗ my-pkg is not registered on npmExit codes: 0 exists · 1 not found · 2 bad usage
API
npmExists(pkg, options?)
| Param | Type | Default | Description |
|---|---|---|---|
| pkg | string | — | Package name |
| options.registry | string | 'https://registry.npmjs.org' | Custom registry URL |
| options.silent | boolean | false | Return false on errors instead of throwing |
Returns Promise<boolean>
getNpmUrl(pkg, registry?)
Returns the registry API URL. Use this directly with your own HTTP client.
License
MIT
