Skip to main content
nh needs three things before most commands work: which server to talk to, a token for it, and the organization and product you mean. You can save each of these, set them in the environment, or pass them as flags.

Where settings come from

nh resolves each setting from these sources, highest precedence first:
  1. A command-line flag, such as --org.
  2. An environment variable. NERVES_HUB_* is read first, then NERVES_CLOUD_*.
  3. The saved settings file, ~/.nh/settings.json.
  4. The built-in default.

Sign in

Sign in through the browser. This is the recommended way. It also works for an account with two-factor authentication, which nh user auth does not.
nh prints a URL and an eight-digit code. Open the URL, sign in to NervesHub, and enter the code. nh waits for you to confirm, then saves your API token. The code lasts five minutes. When stdout is a terminal, nh opens the URL in your browser for you. Pass --no-browser to stop that. It never opens a browser with --non-interactive, or when there is no display, such as over SSH. You can sign in with your email and password instead:
Check who you are signed in as, and sign out:
In CI, do not sign in. Set NERVES_HUB_TOKEN to a user access token or a product API key. See CI and automation.

Set the server

nh talks to NervesCloud at https://manage.nervescloud.com by default. For a self-hosted NervesHub, save your server’s URI before you sign in:
nh status prints the configured URI and whether the server answered its health check. It needs no token, and exits non-zero when the server is unreachable or reports a problem. Signing in with nh user login --uri https://your.nerveshub.host does the same thing: the server you sign in to becomes the default.

The saved token and its server

nh user login and nh user auth save the token together with the server it came from. nh only sends the saved token to that server. If a command would talk to a different server (through --uri, NERVES_HUB_URI, or a later nh config set uri), it fails and names the server the token is for. A token given with --token or NERVES_HUB_TOKEN is always used as it is, with whatever server is configured.

Set a default organization and product

Save the organization and product you use most, so you can leave out --org and --product:
Show or clear saved defaults:
nh config manages uri, org and product only. The token is managed by nh user login, nh user auth and nh user logout, and nh config get never prints it.

Environment variables

Every variable is read with the NERVES_HUB_ prefix and, equivalently, the NERVES_CLOUD_ prefix. When both are set, NERVES_HUB_ wins. Boolean variables accept 1, true, yes, y or on, in any case.

Global flags

Every command accepts these flags.
Use -o json when you parse nh output in a script.

Profiles

A profile is a named snapshot of the active URI, organization, product and token. Use profiles to switch between servers or organizations without signing in again.
Saving under an existing name replaces that profile. Loading a profile replaces the active URI, organization, product and token.

The data directory

nh keeps its state in ~/.nh. Change the location with --data-dir or NERVES_HUB_DATA_DIR.
The data directory holds an API token and signing keys. Do not commit it to version control or share it.