# registry-auth-token

> Get the auth token set for an npm registry (if any)

Latest version **5.1.1** (published 2026-01-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install registry-auth-token
pnpm add registry-auth-token
yarn add registry-auth-token
bun add registry-auth-token
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 5.1.1 |
| Published | 2026-01-16 |
| First published | 2016-03-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=14 |
| Dependencies | 1 |
| Unpacked size | 15.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 33 |
| Author | Espen Hovlandsdal |
| Maintainers | rexxars, leipert, zkochan |
| Keywords | npm, conf, config, npmconf, registry, auth, token, authtoken |

## Links

- npm: https://www.npmjs.com/package/registry-auth-token
- Repository: https://github.com/rexxars/registry-auth-token
- Homepage: https://github.com/rexxars/registry-auth-token#readme
- Issues: https://github.com/rexxars/registry-auth-token/issues
- npm.io page: https://npm.io/package/registry-auth-token

## Dependencies (1)

- [@pnpm/npm-conf](https://npm.io/package/@pnpm/npm-conf.md) ^3.0.2

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 5.1.1 (latest) — 2026-01-16
- 5.1.0 — 2025-02-08
- 5.0.3 — 2024-11-27
- 5.0.2 — 2023-03-05
- 5.0.1 — 2022-06-19
- 5.0.0 — 2022-06-16
- 4.2.2 — 2022-06-16
- 4.2.1 — 2020-11-10
- 4.2.0 — 2020-07-13
- 4.1.1 — 2020-01-22
- 4.1.0 — 2020-01-17
- 4.0.0 — 2019-06-17
- 3.4.0 — 2019-03-20
- 3.3.2 — 2018-01-26
- 3.3.1 — 2017-05-02
- … 13 more at https://npm.io/package/registry-auth-token/versions

## README

# registry-auth-token

[![npm version](http://img.shields.io/npm/v/registry-auth-token.svg?style=flat-square)](https://www.npmjs.com/package/registry-auth-token)[![npm](https://img.shields.io/npm/dm/registry-auth-token?style=flat-square)](https://www.npmjs.com/package/registry-auth-token)

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

## Installing

```
npm install --save registry-auth-token
```

## Usage

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

```js
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(getAuthToken('//registry.foo.bar', {
  npmrc: {
    'registry': 'http://registry.foo.bar',
    '//registry.foo.bar/:_authToken': 'qar'
  }
}))

// Find the configured registry url for scope `@foobar`.
// Falls back to the global registry if not defined.
console.log(getRegistryUrl('@foobar'))

// Use the npm config that is passed in
console.log(getRegistryUrl('http://registry.foobar.eu/', {
  'registry': 'http://registry.foobar.eu/',
  '//registry.foobar.eu/:_authToken': 'qar'
}))
```

## Return value

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

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

// Or, if nothing is found:
undefined
```

## Security

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

## License

MIT © [Espen Hovlandsdal](https://espen.codes/)

---
_Source: https://npm.io/package/registry-auth-token · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
