LinuxCommandLibrary

npm-ping

Check npm registry connectivity

TLDR

Ping the default npm registry

$ npm ping
copy

Ping custom npm registry
$ npm ping --registry [custom_registry_url]
copy

SYNOPSIS

npm ping [--registry=<url>] [--json] [--loglevel=<level>] [-s|--silent]

PARAMETERS

--registry=<url>
    Specifies an alternative registry URL to ping instead of the default or configured one. This allows testing connectivity to specific registries.

--json
    Outputs the command's results in a structured JSON format, useful for scripting and programmatic parsing of the ping status.

--loglevel=<level>
    Sets the verbosity of npm output. Common levels include silent, error, warn, notice, http, info, verbose, and silly. Affects how much detail is shown during the ping operation.

-s, --silent
    Runs the command in silent mode, suppressing progress bars and most informational messages, showing only errors or final results.

DESCRIPTION

The npm ping command, a subcommand of the Node Package Manager (npm) CLI, is a crucial utility for verifying the operational status and user authentication against the configured npm registry. When executed, it sends an authenticated GET request to the /~/ping endpoint of the active registry.

A successful response indicates that the npm CLI can reach the registry and, if logged in, that the user's authentication token is valid. This command is particularly useful for diagnosing network issues, confirming registry availability, or troubleshooting authentication problems before attempting package installations or publications. Its primary function is to provide a quick, lightweight check, returning either a success message, potentially with user details if authenticated, or an error if connectivity or authentication fails. It helps developers confirm their environment is correctly configured to interact with the npm ecosystem.

CAVEATS

The npm ping command, being a subcommand of the primary npm CLI, relies heavily on a functional npm installation and active network connectivity to the target registry. While it verifies authentication, this check is only meaningful if the user is currently logged in via npm login. It does not validate specific package availability or the health of individual registry services beyond the /~/ping endpoint. Users should also be aware that proxy configurations or corporate firewalls can interfere with its operation, even if general internet access is available.

OUTPUT FORMAT

By default, npm ping outputs a human-readable success or error message. When the --json option is used, it returns a JSON object containing ok: true or false, and potentially user information if authenticated successfully (e.g., user: { name: 'your-username' }).

REGISTRY CONFIGURATION

The command respects the currently configured registry setting, which can be found using npm config get registry. This can be overridden for a single command execution using the --registry=<url> flag.

HISTORY

The npm ping command was introduced as a core utility within the Node Package Manager (npm) CLI to address the frequent need for users to quickly ascertain their connection status to the npm registry. Its development was driven by the common troubleshooting scenarios involving network issues, registry outages, or authentication token expirations.

By providing a standardized endpoint (/~/ping) for health checks, it offered a more robust alternative to attempting a dummy npm install for connection verification. It has remained a stable and foundational command, reflecting the npm team's commitment to providing clear diagnostic tools for developers working within the npm ecosystem.

SEE ALSO

npm(1), npm login(1), npm whoami(1), ping(8)

Copied to clipboard