NPM Registry Client (Forked and Maintained)

0.3.2 · maintenance · verified Tue Apr 21

@qiwi/npm-registry-client is a fork of the original `npm-registry-client` package, providing a programmatic interface to interact with the npm registry. It was created to address and fix numerous vulnerabilities present in the upstream package and update its dependencies to a more current state (circa 2020), while also introducing TypeScript typings for improved developer experience. The current stable version is 8.9.1, though its last publish date was approximately five years ago, indicating a maintenance-oriented release cadence rather than active feature development. Key differentiators include its explicit focus on security fixes and type definitions compared to the original `npm-registry-client`, which is now largely unmaintained. It allows applications to fetch package metadata, handle authentication, and perform various registry operations such as retrieving package information.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize the client, configure it for the npm registry, and fetch package metadata (specifically for 'react') using the `get` method, including basic error handling.

import RegClient from '@qiwi/npm-registry-client';

const config = {
  // Required for authenticated operations, e.g., publishing or private registry access.
  // token: process.env.NPM_TOKEN ?? '',
  // username: process.env.NPM_USERNAME ?? '',
  // password: process.env.NPM_PASSWORD ?? '',
  // email: process.env.NPM_EMAIL ?? '',
  
  registry: 'https://registry.npmjs.org/', // Default npm registry URL
  // cache: '/tmp/npm-cache', // Optional: path to cache directory
  // proxy: { http: 'http://my.proxy.com', https: 'http://my.proxy.com' } // Configure proxy if needed
};

const client = new RegClient(config);
const packageName = 'react'; // Example: Fetch metadata for 'react'
const uri = `${config.registry}${packageName}`;
const params = { timeout: 5000 }; // Request timeout in milliseconds

client.get(uri, params, function (error, data, raw, res) {
  if (error) {
    console.error('Failed to fetch package data:', error.message);
    if (error.statusCode === 404) {
      console.error(`Package '${packageName}' not found. Check the package name and registry.`);
    } else if (error.code === 'ETIMEDOUT') {
      console.error('Request timed out. Consider increasing the timeout or checking network.');
    }
    return;
  }

  console.log(`Successfully fetched metadata for ${packageName}@${data['dist-tags'].latest}`);
  console.log('Latest version description:', data.description);
  // console.log('Raw JSON (truncated):', raw.substring(0, 200) + '...'); // The raw JSON string
  // console.log('HTTP Response Status:', res.statusCode); // The full HTTP response object
});

view raw JSON →