Optional configuration for registry URL, downloads API URL, and auth token
Runs a full security audit against the npm registry.
The payload mirrors the top-level structure of package-lock.json:
a name, version, and a dependencies map of resolved packages with their
versions, integrity hashes, and nested sub-dependencies.
Returns detailed advisory objects for every vulnerability found, along with recommended actions (update, install, or manual review).
POST /-/npm/v1/security/audits
Lock-file-shaped dependency tree to audit
Optionalsignal: AbortSignalOptional AbortSignal to cancel the request
Full audit report with advisories, actions, and vulnerability counts
const result = await npm.audit({
name: 'my-app',
version: '1.0.0',
requires: { lodash: '^4.17.11' },
dependencies: {
lodash: { version: '4.17.11', integrity: 'sha512-...' },
},
});
console.log(result.metadata.vulnerabilities);
// { info: 0, low: 0, moderate: 1, high: 0, critical: 0 }
Object.values(result.advisories).forEach(a => {
console.log(`[${a.severity}] ${a.title} — ${a.module_name}@${a.vulnerable_versions}`);
console.log(` Fix: upgrade to ${a.patched_versions}`);
});
Runs a quick security audit against the npm registry.
Same payload as audit but returns only vulnerability counts by severity — no advisory details or recommended actions. Faster and lighter than the full audit.
POST /-/npm/v1/security/audits/quick
Lock-file-shaped dependency tree to audit
Optionalsignal: AbortSignalOptional AbortSignal to cancel the request
Vulnerability counts by severity and dependency totals
const result = await npm.auditQuick({
name: 'my-app',
version: '1.0.0',
requires: { lodash: '^4.17.11' },
dependencies: {
lodash: { version: '4.17.11', integrity: 'sha512-...' },
},
});
const { high, critical } = result.metadata.vulnerabilities;
if (high + critical > 0) {
console.error(`Found ${high} high and ${critical} critical vulnerabilities`);
}
Fetches the total download count for multiple packages.
GET /downloads/point/{period}/{name1},{name2},... (via api.npmjs.org)
npm's bulk lookup accepts at most 128 unscoped packages, so unscoped names
are sent in batches of 128, and each scoped package (@scope/name) is
fetched with its own request.
Package names to fetch downloads for; duplicates are ignored
Named period or date range (default: 'last-month')
Optionalsignal: AbortSignalOptional AbortSignal to cancel the requests
A map of package name to download point data, or null for packages that do not exist
Fetches the per-day download breakdown for a package over a given period.
GET /downloads/range/{period}/{package} (via api.npmjs.org)
Convenience method — equivalent to npm.package(name).downloadRange(period).
Named period or date range
The package name
Optionalsignal: AbortSignalOptional AbortSignal to cancel the request
Download range data with a per-day array
Fetches the total download count for a package over a given period.
GET /downloads/point/{period}/{package} (via api.npmjs.org)
Convenience method — equivalent to npm.package(name).downloads(period).
Named period or date range
The package name
Optionalsignal: AbortSignalOptional AbortSignal to cancel the request
Download point data including total count and date range
Returns a MaintainerResource for a given npm username, providing access to all packages they maintain.
GET /-/v1/search?text=maintainer:{username}
The npm username (e.g. 'sindresorhus', 'pilmee')
A maintainer resource with a packages() method
Unsubscribes a callback previously registered with NpmClient.on. If the callback was registered more than once, only the most recent registration is removed. Unknown callbacks are ignored.
Removing a listener while an event is being emitted does not affect that emission; the change applies from the next request.
Subscribes to a client event. Listener exceptions and rejected promises are isolated from requests. Async listeners are not awaited; callbacks handle their own error reporting.
Returns an OrgResource for a given npm organization, providing authenticated access to org packages, teams, and members.
These endpoints require a registry auth token with org access.
The npm org name, with or without the leading @
An org resource with packages(), teams(), members(), and teamMembers() methods
Returns a PackageResource for a given package name, providing access to package metadata, versions, dist-tags, and download statistics.
The returned resource can be awaited directly to fetch the full packument, or chained to access nested resources.
The package name (e.g. 'react', '@types/node')
A chainable package resource
Searches for packages on the npm registry.
GET /-/v1/search
Search parameters (required: text)
Optionalsignal: AbortSignalOptional AbortSignal to cancel the request
Search results including packages, scores, and total count
Returns top packages for a keyword.
GET /-/v1/search?text=keywords:{keyword}&size={n}
Keyword to filter by
Number of packages to return (default: 20, max: 250)
Optionalsignal: AbortSignalOptional AbortSignal to cancel the request
Search results including packages, scores, and total count
Returns top packages ranked by maintenance.
Number of packages to return (default: 20, max: 250)
Optionalsignal: AbortSignalOptional AbortSignal to cancel the request
Search results including packages, scores, and total count
npm's search API ignores ranking weights, so this returns the
same results as NpmClient.topPackages. To rank by popularity, sort
search results by their downloads field.
GET /-/v1/search?text=keywords:javascript&size={n}&maintenance=1&quality=0&popularity=0
Returns top packages ranked by popularity.
Number of packages to return (default: 20, max: 250)
Optionalsignal: AbortSignalOptional AbortSignal to cancel the request
Search results including packages, scores, and total count
npm's search API ignores ranking weights, so this returns the
same results as NpmClient.topPackages. To rank by popularity, sort
search results by their downloads field.
GET /-/v1/search?text=keywords:javascript&size={n}&popularity=1&quality=0&maintenance=0
Returns top packages ranked by quality.
Number of packages to return (default: 20, max: 250)
Optionalsignal: AbortSignalOptional AbortSignal to cancel the request
Search results including packages, scores, and total count
npm's search API ignores ranking weights, so this returns the
same results as NpmClient.topPackages. To rank by popularity, sort
search results by their downloads field.
GET /-/v1/search?text=keywords:javascript&size={n}&quality=1&popularity=0&maintenance=0
Returns top packages for a scope.
GET /-/v1/search?text=scope:{scope}&size={n}
Scope to filter by, with or without the leading @
Number of packages to return (default: 20, max: 250)
Optionalsignal: AbortSignalOptional AbortSignal to cancel the request
Search results including packages, scores, and total count
Returns the top packages according to npm search's default ranking.
GET /-/v1/search?text=keywords:javascript&size={n}
npm ranks results by search relevance. npm requires a non-empty text
query, so this helper uses a broad JavaScript keyword search.
Number of packages to return (default: 20, max: 250)
Optionalsignal: AbortSignalOptional AbortSignal to cancel the request
Search results including packages, scores, and total count
Returns a UserResource for a given npm username, providing authenticated access to the registry user profile and user package list.
These endpoints require a registry auth token.
The npm username (e.g. 'pilmee')
A user resource with get() and packages() methods
Returns the npm username associated with the configured auth token.
Useful for validating a token and discovering which account it belongs to without knowing the username in advance.
GET /-/whoami
Requires a registry auth token — throws NpmApiError with status 401 if no token is set or the token is invalid.
Optionalsignal: AbortSignalOptional AbortSignal to cancel the request
The username associated with the token
Main entry point for the npm Registry API client.
Example