You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Pau aff9d08cee client 1 year ago
.. client 1 year ago
LICENSE client 1 year ago client 1 year ago
base64.js client 1 year ago
index.js client 1 year ago
package.json client 1 year ago
registry-url.js client 1 year ago


npm versionBuild Status

Get the auth token set for an npm registry from .npmrc. Also allows fetching the configured registry URL for a given npm scope.


npm install --save registry-auth-token


Returns an object containing token and type, or undefined if no token can be found. type can be either Bearer or Basic.

var getAuthToken = require('registry-auth-token')
var getRegistryUrl = require('registry-auth-token/registry-url')

// Get auth token and type for default `registry` set in `.npmrc`
console.log(getAuthToken()) // {token: 'someToken', type: 'Bearer'}

// Get auth token for a specific registry URL

// Find the registry auth token for a given URL (with deep path):
// If registry is at `//`
// URL passed is `//`
// Will find token the closest matching path; `//`
console.log(getAuthToken('//', {recursive: true}))

// Find the configured registry url for scope `@foobar`.
// Falls back to the global registry if not defined.

// Use the npm config that is passed in
console.log(getRegistryUrl('', {
  npmrc: {
    'registry': '',
    '//': 'qar'

Return value

// If auth info can be found:
{token: 'someToken', type: 'Bearer'}

// Or:
{token: 'someOtherToken', type: 'Basic'}

// Or, if nothing is found:


Please be careful when using this. Leaking your auth token is dangerous.


MIT-licensed. See LICENSE.