npm.io
2.1.2 • Published yesterdayCLI

@jayf0x/npm-exists

Licence
MIT
Version
2.1.2
Deps
0
Size
7 kB
Vulns
0
Weekly
21

npm-exists

npm version npm downloads bundle size license

The simplest, fastest possible npm package existence check. One HEAD request, 0 deps

Preview Logo

Install

npm install @jayf0x/npm-exists

Usage

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 npm

Exit 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

Keywords