npm-whoami
Show the current npm username
TLDR
Display username of the currently logged-in user
Display username of the current user in the specific registry
SYNOPSIS
npm whoami [--registry <registry URL>]
npm whoami [--json]
PARAMETERS
--registry <registry URL>
Specifies the npm registry to use for this command. Useful if you're interacting with a private registry different from your default.
--json
Outputs the result in JSON format. When this option is used, the username is returned as a JSON object, e.g., {"username": "your-username"}.
DESCRIPTION
npm-whoami, often invoked simply as npm whoami, is a fundamental command within the Node.js package manager (npm) ecosystem. Its primary purpose is to display the username associated with the currently logged-in npm user on the active npm registry. This command is invaluable for verifying your authentication status, particularly when working with private npm registries, scoped packages, or when troubleshooting publishing and installation issues.
It retrieves the username from the npm configuration, which typically stores authentication tokens. The output is a simple string containing the username, making it easy to parse or use in scripts. Unlike the system's whoami command, which shows the operating system username, npm whoami specifically interacts with your npm credentials. It's a quick and reliable way to confirm which account npm is operating under at any given moment.
CAVEATS
If no user is logged in for the current registry, npm whoami will typically output nothing or an empty string, or it might result in an error message indicating no user is logged in. It does not explicitly state "not logged in."
The command relies on credentials stored in your .npmrc configuration file. If these credentials are invalid or missing, the command will not return a valid username.
It only displays the username and does not provide information about the associated email or other profile details. For more profile details, use npm profile get.
OUTPUT FORMAT
By default, npm whoami outputs only the username as plain text to standard output, followed by a newline. This simplicity makes it ideal for use in shell scripts.
CONFIGURATION SOURCE
The command retrieves the username by checking the authentication token (e.g., _authToken) stored in your .npmrc file, which can be located in your user's home directory or project-specific directories.
REGISTRY CONTEXT
The username displayed is specific to the active npm registry. If you switch registries (e.g., using --registry), the whoami command will attempt to retrieve the username for that particular registry.
HISTORY
The npm whoami command has been a core part of the Node.js package manager (npm) command-line interface since its early development. It leverages a common Unix-like pattern of having a whoami command to identify the current user context, adapted specifically for the npm ecosystem. Its function has remained largely consistent, serving as a straightforward utility to confirm the authenticated npm user, an essential aspect for package publishing and private package access.