JavaScript
The Nhost JavaScript client is the primary way of interacting with your Nhost project. 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({
subdomain: '<your-subdomain>',
region: '<your-region>'
})
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 JavaScript client is written in TypeScript and has full TypeScript support.