Get the set npm registry URL
npx @tessl/cli install tessl/npm-registry-url@7.2.0Get 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.
npm install registry-urlimport registryUrl, { defaultUrl } from 'registry-url';For CommonJS environments:
const registryUrl = require('registry-url').default;
const { defaultUrl } = require('registry-url');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 fallbackRetrieves 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):
npm_config_registry environment variableNPM_CONFIG_REGISTRY environment variable.npmrc: @scope:registry=url.npmrc: registry=urlUsage 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/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
};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/'The package gracefully handles common configuration issues:
No exceptions are thrown - the function always returns a valid registry URL.