or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-registry-url

Get the set npm registry URL

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/registry-url@7.2.x

To install, run

npx @tessl/cli install tessl/npm-registry-url@7.2.0

index.mddocs/

registry-url

Get the set npm registry URL. This utility retrieves the currently configured npm registry URL from environment variables and configuration files, supporting both global registry configuration and scoped package registries.

Package Information

  • Package Name: registry-url
  • Package Type: npm
  • Language: JavaScript (ES modules)
  • Installation: npm install registry-url

Core Imports

import registryUrl, { defaultUrl } from 'registry-url';

For CommonJS environments:

const registryUrl = require('registry-url').default;
const { defaultUrl } = require('registry-url');

Basic Usage

import registryUrl, { defaultUrl } from 'registry-url';

// Get the configured registry URL
console.log(registryUrl());
//=> 'https://registry.npmjs.org/' (or your configured registry)

// Get the default npm registry URL
console.log(defaultUrl);
//=> 'https://registry.npmjs.org/'

// Get registry URL for a specific scope
console.log(registryUrl('@mycompany'));
//=> URL configured for @mycompany scope or fallback

Capabilities

Registry URL Resolution

Retrieves the npm registry URL based on configuration priority: environment variables, .npmrc files, and fallback to default.

/**
 * Get the npm registry URL for the given scope or global registry
 * @param scope - Optional npm scope (e.g., '@mycompany')
 * @returns Registry URL, always ending with trailing slash
 */
function registryUrl(scope?: string): string;

Configuration Priority (highest to lowest):

  1. npm_config_registry environment variable
  2. NPM_CONFIG_REGISTRY environment variable
  3. Scoped registry from .npmrc: @scope:registry=url
  4. General registry from .npmrc: registry=url
  5. Default npm registry

Usage Examples:

// Global registry (checks env vars, then .npmrc, then default)
const globalRegistry = registryUrl();

// Scoped registry (checks scope config, then falls back to global logic)
const scopedRegistry = registryUrl('@mycompany');

Configuration Examples:

Environment variable configuration:

export npm_config_registry="https://my-registry.com/"

.npmrc file configuration:

# Global registry
registry=https://my-registry.com/

# Scoped registry
@mycompany:registry=https://company-registry.com/

Default Registry URL

The standard npm registry URL constant.

/**
 * The default npm registry URL
 */
const defaultUrl: string;

Value: "https://registry.npmjs.org/"

Usage Examples:

import { defaultUrl } from 'registry-url';

// Use as fallback or for comparison
if (currentRegistry === defaultUrl) {
  console.log('Using default npm registry');
}

// Use in configuration
const config = {
  registry: process.env.CUSTOM_REGISTRY || defaultUrl
};

URL Normalization

All returned URLs are automatically normalized to include a trailing slash, ensuring consistency for registry API calls.

// Input: 'https://registry.example.com'
// Output: 'https://registry.example.com/'

Error Handling

The package gracefully handles common configuration issues:

  • Missing .npmrc files: Falls back to environment variables or default
  • Invalid .npmrc content: Uses what can be parsed, falls back gracefully
  • Missing scope configuration: Falls back to general registry configuration
  • Missing environment variables: Uses .npmrc or default registry

No exceptions are thrown - the function always returns a valid registry URL.

Platform Requirements

  • Node.js: >= 18
  • Module System: ES modules (with CommonJS compatibility via exports field)
  • Platform: Cross-platform (Windows, macOS, Linux)