Nhost Dev

#Nhost Dev

nhost dev starts your local development environment.

$ nhost dev

⠇ Nhost is starting...

# The first time dev is run takes a bit longer because the database is being created

✔ Local Nhost backend is running!
GraphQL API:    http://localhost:8080/v1/graphql
Hasura Console: http://localhost:9695
Auth & Storage: http://localhost:9000
API:            http://localhost:4000

The local websocket url is ws://localhost:8080/v1/graphql

Great! You now have a Nhost backend locally with all services:

  • PostgreSQL
  • Hasura GraphQL Engine
  • Hasura Backend Plus
  • Custom API

The Hasura console (https://localhost:9695) was launched. Use this URL specifically to make changes in Hasura to track migrations and metadata automatically (recommended). All metadata and migrations are stored in the nhost/ folder.

#Logs

Get local logs for each service when you develop locally.

PostgreSQL

$ docker logs -f nhost_postgres

Hasura GraphQL Engine

$ docker logs -f nhost_hasura

Hasura Backend Plus

$ docker logs -f nhost_hbp

Custom API

$ docker logs -f nhost_api

#Configuration

Note that for the below configurations to take effect, you need to restart nhost dev.

Permission variables

To add permission variables to the JWT token set JWT_CUSTOM_FIELDS in .env.development.

Example: if every user has a company_id column that should be used as a permission variable in the JWT token (x-hasura-company-id):

.env.development
JWT_CUSTOM_FIELDS=company_id

Registration custom fields

To add registration custom fields set REGISTRATION_CUSTOM_FIELDS in .env.development

Example: If users should be able to set display_name on registration.

.env.development
REGISTRATION_CUSTOM_FIELDS=display_name

#Networking

The docker containers all expose their ports directly on the host machine, so you can both reach them on localhost as well as on the host machine IP address from another machine connected to the same network (if firewall rules allows).

Expo

In Expo, to make development use the dev environment both in the simulator and in Expo Go and production use production, see code below:

export const URL =
  Constants.manifest.packagerOpts.dev && !Constants.isDevice
    ? "http://localhost:9001"
    : typeof manifest.packagerOpts === `object` && manifest.packagerOpts.dev
    ? `http://${manifest.debuggerHost.split(`:`).shift().concat(`:9001`)}`
    : "nhost.io cloud url";