package
Get the auth token set for an npm registry (if any)
npm install registry-auth-tokenGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 8 packages.
105.8 kB
Includes dependencies.
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-tokenReturns an object containing token and type, or undefined if no token can be found. type can be either Bearer or Basic.
const getAuthToken = require('registry-auth-token')
const 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
console.log(getAuthToken('//registry.foo.bar'))
// Find the registry auth token for a given URL (with deep path):
// If registry is at `//some.host/registry`
// URL passed is `//some.host/registry/deep/path`
// Will find token the closest matching path; `//some.host/registry`
console.log(getAuthToken('//some.host/registry/deep/path', {recursive: true}))
// Use the npm config that is passed in
console.log
// If auth info can be found:
{token: 'someToken', type: 'Bearer'}
// Or:
{token: 'someOtherToken', type: 'Basic'}
// Or, if nothing is found:
undefinedPlease be careful when using this. Leaking your auth token is dangerous.
MIT © Espen Hovlandsdal
leipert
git@leipert.io