Overview
The Nhost client is the primary way of interacting with your Nhost app. It exposes a standard interface for each of the following services:
Installation
Install the the Nhost client together with GraphQL:
- npm
- Yarn
npm install @nhost/nhost-js graphql
yarn add @nhost/nhost-js graphql
Initializing
Initialize a single nhost
instance using your Nhost backend URL:
import { NhostClient } from '@nhost/nhost-js'
const nhost = new NhostClient({
backendUrl: '<Your Nhost Backend URL>'
})
GraphQL Support
The Nhost client has a small GraphQL client built-in which is great to use server-side or in very simple frontend apps. For more serious frontend apps, we recommend using a more complete GraphQL client such as:
Tokens and Permissions
The Nhost client manages refresh tokens and access tokens automatically. The correct authorization headers are set if the user is signed in. Both access tokens and refresh tokens are automatically refreshed in the background.
If the user is not signed in no authorization header is set. If no authorization header is set, requests to GraphQL and Storage resolve permissions using the public
role.
TypeScript Support
The Nhost JS SDK has TypeScript typings included. You don’t have to import types separately.