Skip to main content

CLI

Nhost CLI, or nhost, is a command-line interface that lets you run and manage Nhost projects locally on Mac, Linux and Windows (WSL2).

This means you get a full-featured Nhost project running locally on your machine:

  • Postgres Database
  • Hasura GraphQL API
  • Hasura Console
  • Auth
  • Storage
  • Serverless Functions

This way, you can develop and test local changes before you deploy them live. The CLI automatically tracks:

  • Postgres database migrations
  • Hasura metadata
  • Serverless functions

It's recommended to commit and push changes to GitHub and use the GitHub integration for Nhost to automatically deploy those changes live.

Installation

To download and install Nhost CLI, run the following command:

sudo curl -L https://raw.githubusercontent.com/nhost/cli/main/get.sh | bash

Dependencies

The following dependencies are required:

  • Git
  • Docker (must be running while using the CLI)
info

Make sure you have the correct permissions for Docker so you don't have to run Docker with sudo. See "Post-installation steps for Linux" from Docker's documentation.

Get started

Start by authenticating yourself to Nhost Cloud:

nhost login

Once signed in, you can list all your Nhost projects using:

nhost list

Let's start by initializing a remote Nhost project locally with the following command:

nhost init --remote

Pick a Nhost project to use then change the directory once the project initialization is completed:

cd my_test_app

Then start the Nhost project locally:

nhost up

Hasura Console starts automatically and your Nhost project is running locally with the backend URL: http://localhost:1337.

Subdomain and Region

Use localhost:1337 as the subdomain, and skip region when using the CLI and the JavaScript SDK:

import { NhostClient } from '@nhost/nhost-js'

const nhost = new NhostClient({
subdomain: 'localhost:1337',
})

Emails

During local development with the CLI, all transactional emails from Authentication are sent to a local Mailhog instance, instead of to the recipient's email address. You'll see an address where after starting nhost up where all emails are sent to.

For the example below, all emails are accessable at http://localhost:8839.

$ nhost up
✔ Your app is running at http://localhost:1337 (Ctrl+C to stop)
ℹ Emails will be sent to http://localhost:8839

What's next?