3 [![npm version](http://img.shields.io/npm/v/registry-auth-token.svg?style=flat-square)](http://browsenpm.org/package/registry-auth-token)[![Build Status](http://img.shields.io/travis/rexxars/registry-auth-token/master.svg?style=flat-square)](https://travis-ci.org/rexxars/registry-auth-token)
5 Get the auth token set for an npm registry from `.npmrc`. Also allows fetching the configured registry URL for a given npm scope.
10 npm install --save registry-auth-token
15 Returns an object containing `token` and `type`, or `undefined` if no token can be found. `type` can be either `Bearer` or `Basic`.
18 var getAuthToken = require('registry-auth-token')
19 var getRegistryUrl = require('registry-auth-token/registry-url')
21 // Get auth token and type for default `registry` set in `.npmrc`
22 console.log(getAuthToken()) // {token: 'someToken', type: 'Bearer'}
24 // Get auth token for a specific registry URL
25 console.log(getAuthToken('//registry.foo.bar'))
27 // Find the registry auth token for a given URL (with deep path):
28 // If registry is at `//some.host/registry`
29 // URL passed is `//some.host/registry/deep/path`
30 // Will find token the closest matching path; `//some.host/registry`
31 console.log(getAuthToken('//some.host/registry/deep/path', {recursive: true}))
33 // Find the configured registry url for scope `@foobar`.
34 // Falls back to the global registry if not defined.
35 console.log(getRegistryUrl('@foobar'))
37 // Use the npm config that is passed in
38 console.log(getRegistryUrl('http://registry.foobar.eu/', {
40 'registry': 'http://registry.foobar.eu/',
41 '//registry.foobar.eu/:_authToken': 'qar'
49 // If auth info can be found:
50 {token: 'someToken', type: 'Bearer'}
53 {token: 'someOtherToken', type: 'Basic'}
55 // Or, if nothing is found:
61 Please be careful when using this. Leaking your auth token is dangerous.
65 MIT-licensed. See LICENSE.