Skip to content

Instantly share code, notes, and snippets.

@agwells
Last active August 1, 2021 22:29
Show Gist options
  • Save agwells/bd3f237879a39e76f12a0cb42f1c2fcf to your computer and use it in GitHub Desktop.
Save agwells/bd3f237879a39e76f12a0cb42f1c2fcf to your computer and use it in GitHub Desktop.
Manually setting up an npm auth token (without using `npm login`)

I was annoyed to find tha the NPM website lets you generate auth tokens manually, but does not provide any instructions on how to configure them in your local workspace. The only instructions are to give your username and password to npm login, which will then configure our workspace.

But all npm login does is pop the token into some annoyingly undocumented config fields in ~.npmrc. You can just as easily do this manually, if you would rather not type your password into a terminal script.

  1. Log in to the NPM website and generate an auth token.
  2. Put it in your ~/.npmrc file like so:
//registry.npmjs.org/:_authToken=YOUR-TOKEN-WOULD-GO-HERE
  1. (Highly recommended): After you're done with your npm session, run npm logout. This will invalidate the token and remove it from your ~/.npmrc file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment