Skip to content
Latchkey

npm login: Usage, Options & Common CI Errors

Authenticate to an npm registry.

npm login (alias npm adduser) authenticates you to a registry and stores the auth token in .npmrc. It is interactive, so CI uses a pre-provisioned token instead.

What it does

Prompts for credentials (or opens a browser for the web login flow) and writes an auth token to your user .npmrc for the configured registry. --scope and --registry target a specific scope or private registry.

Common usage

Terminal
npm login                                   # default registry
npm login --scope=@acme --registry=https://npm.acme.dev
npm whoami                                  # confirm who you are

Common CI error: npm login hangs

A CI job calling npm login blocks forever on the interactive prompt. Do not run npm login in CI - write an automation token straight into .npmrc so npm publish/install authenticates without prompting.

.github/workflows/release.yml
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
npm whoami                                  # verify auth

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →