Registry / http-networking / npm-api

npm-api

JSON →
library1.0.1jsnpmunverified

This Node.js library, `npm-api` (current stable version 1.0.1), provides a programmatic interface for interacting with the public NPM registry API, primarily through its CouchDB views. It allows developers to fetch package metadata, retrieve maintainer information, and query registry data using its `NpmApi` client and associated `Repo` and `Maintainer` models. The library simplifies what would otherwise be direct HTTP requests to the registry, offering methods to get package details, specific versions, and a maintainer's list of repositories. While it once served as a convenient wrapper, the package has not received updates in approximately five years, indicating it is likely abandoned and should be used with caution, particularly for new projects requiring active support or modern features.

npm install npm-api
INSTALL
IMPORT
SIG · NPM-API
N
npm-api
http-networkingjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

NpmApi
const NpmApi = require('npm-api');
import NpmApi from 'npm-api';
The primary client constructor. This package is CommonJS-only and does not natively support ESM imports. The `NpmApi` class is the default export.
Repo
const Repo = require('npm-api/lib/models/repo');
const { Repo } = require('npm-api');
The `Repo` model can be instantiated directly for advanced use cases, but it is typically obtained via an `NpmApi` instance (e.g., `new NpmApi().repo('name')`). Direct import requires specifying the sub-path as it's not a root export. The README's example `new Repo()` is misleading without showing the full import path.
Maintainer
const Maintainer = require('npm-api/lib/models/maintainer');
const { Maintainer } = require('npm-api');
The `Maintainer` model can be instantiated directly, but it is typically obtained via an `NpmApi` instance (e.g., `new NpmApi().maintainer('name')`). Direct import requires specifying the sub-path as it's not a root export. The README's example `new Maintainer()` is misleading without showing the full import path.

Demonstrates fetching package details for 'express' and listing repositories for 'ljharb' using the `NpmApi` client.

const NpmApi = require('npm-api'); async function getNpmInfo() { const npm = new NpmApi(); // Get info for a specific repository via the NpmApi instance console.log('--- Repository Info ---'); const repo = npm.repo('express'); try { const pkg = await repo.package(); console.log(`Package: ${pkg.name}@${pkg.version}`); console.log(`Description: ${pkg.description}`); console.log(`Maintainers: ${pkg.maintainers.map(m => m.name).join(', ')}`); } catch (err) { console.error(`Error fetching express package: ${err.message}`); } // Get info for a specific maintainer via the NpmApi instance console.log('\n--- Maintainer Info ---'); const maintainer = npm.maintainer('ljharb'); try { const repos = await maintainer.repos(); console.log(`Maintainer ljharb manages ${repos.length} repositories.`); console.log('Some of their repos:'); repos.slice(0, 3).forEach(r => console.log(`- ${r}`)); } catch (err) { console.error(`Error fetching maintainer repos: ${err.message}`); } } getNpmInfo();
Debug
Known issues
breakingThe `npm-api` package has not been updated in approximately five years, indicating it is no longer actively maintained. Users should be aware of potential compatibility issues with newer Node.js versions or changes in the NPM registry API that may not be addressed.
fix
Consider using alternative, actively maintained NPM registry clients or making direct HTTP requests to the official NPM registry API endpoints.
affects: >=1.0.1
gotchaThe README examples for `new Maintainer()` and `new Repo()` are misleading. These classes are not directly exported from the main `npm-api` package. Attempting `const { Maintainer } = require('npm-api');` will result in `undefined`.
fix
To directly import and instantiate `Maintainer` or `Repo`, you must use specific sub-paths: `require('npm-api/lib/models/maintainer')` or `require('npm-api/lib/models/repo')`. Alternatively, obtain instances via the `NpmApi` client: `new NpmApi().maintainer('name')` or `new NpmApi().repo('name')`.
affects: >=1.0.0
gotchaThis package is strictly CommonJS (CJS) and does not support ES Modules (ESM) syntax. Attempting `import NpmApi from 'npm-api';` in an ESM context will throw a `TypeError`.
fix
Always use `require()` syntax for importing `npm-api` and its sub-modules: `const NpmApi = require('npm-api');`. If used in an ESM project, consider dynamic import (`await import('npm-api')`) or a CJS wrapper.
affects: >=1.0.0
gotchaThe NPM registry API, particularly the CouchDB views that this library heavily relies on, may change or become less reliable over time. Given the package's abandoned status, it might not adapt to future API changes, potentially leading to unexpected errors or incomplete data.
fix
Regularly test critical integrations with this library. Be prepared to implement custom logic to interact with the current NPM registry API endpoints if this library's methods fail or return incorrect data.
affects: >=1.0.1
Errors
Common errors & fixes
TypeError: Maintainer is not a constructor
Attempting to instantiate `Maintainer` or `Repo` directly (e.g., `new Maintainer('name')`) without correctly importing the class.
fix
Import the class from its specific sub-path: `const Maintainer = require('npm-api/lib/models/maintainer');` or use the `NpmApi` client method: `const npm = new NpmApi(); const maintainer = npm.maintainer('name');`.
Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported. Instead change the require of index.js in ... to a dynamic import() call.
Trying to use `require()` to import `npm-api` within an ES Module (ESM) context, or vice-versa with `import` in CJS.
fix
Ensure your project or file uses CommonJS (`.js` files without `"type": "module"` in `package.json` or explicit `.cjs` extension) or use dynamic `import()`: `const NpmApi = await import('npm-api');`.
Error: Not Found - no such package available
The `repo` or `package` method was called with a package name that does not exist in the NPM registry.
fix
Verify the package name is correct and published on npm. Ensure there are no typos. This error can also occur if the registry URL is inaccessible or has changed, though less likely for public packages.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources