registry-info
raw JSON → 1.0.0 verified Sat Apr 25 auth: no javascript
Get npm registry information including URL, auth token, and authorization header from a given scope or default. Version 1.0.0. This is a small utility that combines registry-auth-token and registry-url to provide a unified API. It is useful for tooling that needs to interact with private npm registries. The package is mature and stable, with no recent updates. It supports both default registry and scoped registries. Alternative: directly using registry-auth-token and registry-url separately.
Common errors
error TypeError: registryInfo is not a function ↓
cause Using named import instead of default import.
fix
Use
import registryInfo from 'registry-info' instead of import { registryInfo } from 'registry-info'. error Cannot find module 'registry-info' ↓
cause Package not installed in node_modules or path issue.
fix
Run
npm install registry-info --save and ensure the package is in your dependencies. error registryInfo is not defined ↓
cause Using CommonJS require without default assignment properly.
fix
Use
const registryInfo = require('registry-info').default; or better switch to ES imports. Warnings
gotcha The function returns authToken and authorization as undefined if no auth is found. You may need to check for undefined before using. ↓
fix Check if authToken or authorization exist before using in headers: const { authorization } = registryInfo(); if (authorization) { headers['Authorization'] = authorization; }
deprecated The 'registry-auth-token' dependency may have breaking changes in newer versions. Ensure compatible versions are used. ↓
fix Pin versions in package.json: "registry-auth-token": "3.x", "registry-url": "5.x"
gotcha The package expects the npm token to be set in .npmrc or environment variables. If not set, authToken will be undefined. ↓
fix Set npm token: npm config set //registry.npmjs.org/:_authToken=YOUR_TOKEN
Install
npm install registry-info yarn add registry-info pnpm add registry-info Imports
- default wrong
const registryInfo = require('registry-info')correctimport registryInfo from 'registry-info' - registryInfo wrong
import { registryInfo } from 'registry-info'correctimport registryInfo from 'registry-info' - type usage wrong
const { registryUrl, authToken, authorization } = require('registry-info')()correctimport registryInfo from 'registry-info'; const info = registryInfo();
Quickstart
import registryInfo from 'registry-info';
// Get info for default registry
const info = registryInfo();
console.log(info);
// { registryUrl: 'https://registry.npmjs.org/', authToken: undefined, authorization: undefined }
// Get info for a scoped registry (e.g. @myco)
const scopedInfo = registryInfo('@myco');
console.log(scopedInfo);
// { registryUrl: 'https://registry.myco.com/', authToken: '...', authorization: 'Bearer ...' }