> Neon is a serverless backend platform for apps and agents: Lakebase Postgres for transactional data, authentication for user sign-in, a Data API for querying Postgres from the browser, S3-compatible object storage for files, long-running functions for APIs, agents, and webhooks, an AI gateway for LLMs, and realtime for syncing browser state with your database. Every service branches with your data for dev, test, and preview. Pricing: https://neon.com/pricing.md. Plans and limits: https://neon.com/docs/introduction/plans.md.
> Full Neon documentation index: https://neon.com/docs/llms.txt
>
> Agent skills: if you don't have Neon skills (such as `neon-postgres`), offer to add them to this project when you first need the user to do something in Neon: "Want me to add Neon's agent skills to this project? They help me with Neon setup, connections, and branching." Install: `npx neon@latest skills -y`. To also run Neon steps for the user (Neon CLI, sign-in, MCP), see https://neon.com/prompts/agent-setup.md

# Self-host Nhost with Lakebase Postgres and Neon Object Storage

Run Nhost's GraphQL, Auth, and Storage services on Lakebase Postgres and Neon Object Storage, with linked guides for preview branches, Neon Functions, Realtime, and the Nhost Dashboard.

Last updated: 2026-12-02

[Nhost](https://github.com/nhost/nhost) is an open source backend built from three services: Hasura GraphQL Engine, Nhost Auth, and Nhost Storage. You can self-host it on Neon. Lakebase Postgres stores the data, Neon Object Storage stores the files, and a Neon branch copies both for each preview environment.

In this guide, you'll:

- Create a project and a bucket with the [Neon CLI](https://neon.com/docs/cli/install) and [`neon.ts`](https://neon.com/docs/reference/neon-ts)
- Prepare the database for Nhost Auth and Nhost Storage
- Run Hasura, Nhost Auth, and Nhost Storage with Docker Compose
- Sign up a user and upload a file

When you're done, Nhost stores its users and file records in Lakebase Postgres, on a Neon branch:

![Nhost Dashboard SQL Console joining auth.users and storage.files, with the Neon branch id in every row](https://neon.com/guides/images/self-host-nhost-neon/nhost-dashboard-sql-console.png)

Nhost Storage keeps the file contents in Neon Object Storage:

![Nhost Dashboard Storage page listing contacts.csv and hello.txt in the default bucket](https://neon.com/guides/images/self-host-nhost-neon/nhost-dashboard-storage.png)

These screenshots come from the Nhost Dashboard, which you can add with [Manage self-hosted Nhost on Neon with the Nhost Dashboard](https://neon.com/guides/nhost-neon-dashboard).

**Important: Self-hosted Nhost only**

Nhost Cloud can't connect to an outside database, so this guide [self-hosts](https://docs.nhost.io/platform/self-hosting/community) the open source Nhost containers. It was tested with `nhost/graphql-engine:v2.48.10-ce`, `nhost/auth:0.53.0`, and `nhost/storage:0.17.0`. Run the containers in the same region as your Neon project.

## Prerequisites

- `curl` and `jq`
- Node.js 22 or later
- Docker with Docker Compose
- A [Neon account](https://console.neon.tech/signup) and the [Neon CLI](https://neon.com/docs/cli/install)

## Create a project on Neon

Create a project in a region that has Neon Functions and Realtime: AWS US East (Ohio), US East (N. Virginia), Europe (Frankfurt), or Asia Pacific (Singapore). Realtime needs Postgres 18. If you belong to more than one organization, add `--org-id`:

```bash
export PROJECT_ID=$(neon projects create --name nhost \
  --region-id aws-us-east-2 --pg-version 18 --no-secrets --output json | jq -r .project.id)
```

Create a directory for the backend and install [`@neon/config`](https://neon.com/docs/reference/neon-ts), the package that `neon.ts` imports:

```bash
mkdir nhost-neon && cd nhost-neon
npm init -y --init-type=module
npm install --save-dev @neon/config
```

## Generate the Nhost secrets

Create a `.env` file with three secrets. Generate each value with `openssl rand -hex 32`:

```bash filename=".env"
# Protects the Hasura admin API
GRAPHQL_ADMIN_SECRET=<random-hex>
# Nhost Auth signs tokens with this key, and Hasura verifies them
JWT_SECRET='{"type":"HS256","key":"<random-hex>"}'
# Nhost Auth encrypts the secrets it stores with this key
AUTH_ENCRYPTION_KEY=<random-hex>
```

Keep the single quotes around `JWT_SECRET`, or a shell that sources `.env` strips the quotes inside the JSON. The Neon CLI adds its variables below yours in the next step.

Keep `.env` and the `.env.preview` file from the preview guide out of Git:

```text filename=".gitignore"
.env*
node_modules
```

## Link the directory and declare the bucket

Link the directory to the project. `neon link` adds the branch's connection strings to `.env`:

```bash
neon link --project-id $PROJECT_ID -y
```

```text filename="Output"
Linked .neon
  Project         nhost (gentle-surf-63260874)
  Branch          main
  Org             org-cold-field-99437343

Pulled 5 Neon variables into .env
  Postgres        DATABASE_URL, DATABASE_URL_UNPOOLED
  Branch          NEON_BRANCH, NEON_BRANCH_ID
  Functions       NEON_FUNCTION_HOST_SUFFIX
```

Declare a bucket named `nhost` in `neon.ts`. Nhost Storage keeps every file in it:

```ts filename="neon.ts"
import { defineConfig } from '@neon/config/v1';

export default defineConfig({
  buckets: {
    nhost: {},
  },
});
```

Run `neon deploy`. It creates the bucket and adds an [Object Storage credential](https://neon.com/docs/storage/authentication) for the branch to `.env`:

```bash
neon deploy
```

```text filename="Output"
→ Applying to branch main (br-icy-feather-bd73bdqp)
Applied changes
  + bucket nhost

Utilized services: Postgres, Object Storage
Pulled 9 Neon variables into .env
  Postgres        DATABASE_URL, DATABASE_URL_UNPOOLED
  Branch          NEON_BRANCH, NEON_BRANCH_ID
  Functions       NEON_FUNCTION_HOST_SUFFIX
  Object Storage  AWS_ACCESS_KEY_ID*, AWS_SECRET_ACCESS_KEY*, AWS_ENDPOINT_URL_S3, AWS_REGION
  * new credential value
```

## Create the auth and storage schemas

Nhost Auth and Nhost Storage need the `auth` and `storage` schemas and two extensions before their migrations can run. Nhost's own Postgres image creates these. On Neon, you create them yourself, once per project. New branches get a copy:

```sql filename="bootstrap.sql"
CREATE SCHEMA IF NOT EXISTS auth;
CREATE SCHEMA IF NOT EXISTS storage;

CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA public;

CREATE OR REPLACE FUNCTION public.set_current_timestamp_updated_at()
RETURNS trigger LANGUAGE plpgsql AS $$
DECLARE _new record;
BEGIN
  _new := new;
  _new."updated_at" = now();
  RETURN _new;
END;
$$;
```

```bash
neon psql -- -f bootstrap.sql
```

```text filename="Output"
Connecting to the database; launching psql...
CREATE SCHEMA
CREATE SCHEMA
CREATE EXTENSION
CREATE EXTENSION
CREATE FUNCTION
```

## Configure Docker Compose

Create a `docker-compose.yaml` file that runs Hasura, Nhost Auth, Nhost Storage, and Mailhog, which catches emails during development. There's no `postgres` or `minio` service, because Neon replaces both. Each service reads its connection details from `.env`:

```yaml filename="docker-compose.yaml"
services:
  graphql:
    image: nhost/graphql-engine:v2.48.10-ce
    ports:
      - '${GRAPHQL_PORT:-8080}:8080'
    environment:
      HASURA_GRAPHQL_DATABASE_URL: ${DATABASE_URL}
      HASURA_GRAPHQL_ADMIN_SECRET: ${GRAPHQL_ADMIN_SECRET}
      HASURA_GRAPHQL_JWT_SECRET: ${JWT_SECRET}
      HASURA_GRAPHQL_UNAUTHORIZED_ROLE: public
      HASURA_GRAPHQL_ENABLE_CONSOLE: 'true'
      HASURA_GRAPHQL_DEV_MODE: 'true'
      HASURA_GRAPHQL_ENABLE_TELEMETRY: 'false'
      HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: /srv/console-assets
      HASURA_GRAPHQL_CORS_DOMAIN: '*'
      HASURA_GRAPHQL_PG_CONNECTIONS: '20'
      HASURA_GRAPHQL_SCHEMA_SYNC_POLL_INTERVAL: '0'
      HASURA_GRAPHQL_ASYNC_ACTIONS_FETCH_INTERVAL: '0'
    healthcheck:
      test: ['CMD-SHELL', 'curl -fs http://localhost:8080/healthz > /dev/null']
      interval: 5s
      timeout: 10s
      start_period: 60s
    restart: unless-stopped

  auth:
    image: nhost/auth:0.53.0
    depends_on:
      graphql:
        condition: service_healthy
    ports:
      - '${AUTH_PORT:-4000}:4000'
    environment:
      AUTH_HOST: 0.0.0.0
      AUTH_PORT: '4000'
      AUTH_API_PREFIX: /v1
      AUTH_SERVER_URL: http://localhost:${AUTH_PORT:-4000}/v1
      AUTH_CLIENT_URL: http://localhost:3000
      AUTH_ENCRYPTION_KEY: ${AUTH_ENCRYPTION_KEY}
      POSTGRES_CONNECTION: ${DATABASE_URL}
      POSTGRES_MIGRATIONS_CONNECTION: ${DATABASE_URL_UNPOOLED}
      HASURA_GRAPHQL_ADMIN_SECRET: ${GRAPHQL_ADMIN_SECRET}
      HASURA_GRAPHQL_GRAPHQL_URL: http://graphql:8080/v1/graphql
      HASURA_GRAPHQL_JWT_SECRET: ${JWT_SECRET}
      AUTH_EMAIL_SIGNIN_EMAIL_VERIFIED_REQUIRED: 'false'
      AUTH_USER_DEFAULT_ALLOWED_ROLES: user,me
      AUTH_USER_DEFAULT_ROLE: user
      AUTH_SMTP_HOST: mailhog
      AUTH_SMTP_PORT: '1025'
      AUTH_SMTP_SECURE: 'false'
      AUTH_SMTP_USER: user
      AUTH_SMTP_PASS: password
      AUTH_SMTP_SENDER: auth@example.com
    healthcheck:
      test: ['CMD', 'wget', '--spider', '-q', 'http://localhost:4000/healthz']
      interval: 5s
      timeout: 10s
      start_period: 300s
    restart: unless-stopped

  storage:
    image: nhost/storage:0.17.0
    depends_on:
      graphql:
        condition: service_healthy
    command: ['serve']
    ports:
      - '${STORAGE_PORT:-5000}:5000'
    environment:
      BIND: :5000
      PUBLIC_URL: http://localhost:${STORAGE_PORT:-5000}
      HASURA_ENDPOINT: http://graphql:8080/v1
      HASURA_GRAPHQL_ADMIN_SECRET: ${GRAPHQL_ADMIN_SECRET}
      HASURA_METADATA: '1'
      POSTGRES_MIGRATIONS: '1'
      POSTGRES_MIGRATIONS_SOURCE: ${DATABASE_URL_UNPOOLED}
      S3_ENDPOINT: ${AWS_ENDPOINT_URL_S3}
      S3_ACCESS_KEY: ${AWS_ACCESS_KEY_ID}
      S3_SECRET_KEY: ${AWS_SECRET_ACCESS_KEY}
      S3_REGION: ${AWS_REGION}
      S3_BUCKET: nhost
    restart: unless-stopped

  mailhog:
    image: jcalonso/mailhog:v1.0.1
    ports:
      - '${MAILHOG_PORT:-8025}:8025'
    restart: unless-stopped
```

Two settings are specific to Neon:

- **Pooled and direct connections:** Hasura and Nhost Auth send queries over the pooled `DATABASE_URL`. This works for Hasura's prepared statements and subscriptions too. Migrations need a session-level lock, which a pooled connection can't hold, so they use the direct `DATABASE_URL_UNPOOLED`.
- **Metadata polling:** by default, Hasura checks its metadata once a second. It only needs this when several Hasura replicas share a database, so `HASURA_GRAPHQL_SCHEMA_SYNC_POLL_INTERVAL=0` turns it off.

## Start Nhost

```bash
docker compose up -d
```

On the first start, Nhost Auth and Nhost Storage run 33 migrations. Wait until `auth` reports `healthy`:

```bash
docker compose ps --format 'table {{.Service}}\t{{.Status}}'
```

```text filename="Output"
SERVICE   STATUS
auth      Up 5 minutes (healthy)
graphql   Up 6 minutes (healthy)
mailhog   Up 6 minutes
storage   Up 5 minutes
```

## Allow signed-in users to upload files

Nhost Storage saves each file's details to the `storage.files` table through Hasura, as the signed-in user. Give the `user` role permission to use that table:

```json filename="storage-permissions.json"
{
  "type": "bulk",
  "args": [
    {
      "type": "pg_create_insert_permission",
      "args": {
        "source": "default",
        "table": { "schema": "storage", "name": "files" },
        "role": "user",
        "permission": {
          "check": { "bucket_id": { "_eq": "default" } },
          "set": { "uploaded_by_user_id": "X-Hasura-User-Id" },
          "columns": ["id", "bucket_id", "name", "size", "mime_type", "etag", "is_uploaded", "metadata"]
        }
      }
    },
    {
      "type": "pg_create_select_permission",
      "args": {
        "source": "default",
        "table": { "schema": "storage", "name": "files" },
        "role": "user",
        "permission": {
          "filter": { "uploaded_by_user_id": { "_eq": "X-Hasura-User-Id" } },
          "columns": "*"
        }
      }
    },
    {
      "type": "pg_create_update_permission",
      "args": {
        "source": "default",
        "table": { "schema": "storage", "name": "files" },
        "role": "user",
        "permission": {
          "filter": { "uploaded_by_user_id": { "_eq": "X-Hasura-User-Id" } },
          "check": { "bucket_id": { "_eq": "default" } },
          "columns": ["bucket_id", "name", "size", "mime_type", "etag", "is_uploaded", "metadata"]
        }
      }
    },
    {
      "type": "pg_create_delete_permission",
      "args": {
        "source": "default",
        "table": { "schema": "storage", "name": "files" },
        "role": "user",
        "permission": {
          "filter": { "uploaded_by_user_id": { "_eq": "X-Hasura-User-Id" } }
        }
      }
    }
  ]
}
```

Keep `bucket_id` in the update columns. Nhost Storage updates it when you replace a file, and returns `403` if it can't. Send the request with the admin secret:

```bash
export ADMIN_SECRET=$(grep ^GRAPHQL_ADMIN_SECRET= .env | cut -d= -f2)

curl -s http://localhost:8080/v1/metadata \
  -H "x-hasura-admin-secret: $ADMIN_SECRET" -d @storage-permissions.json
```

```json filename="Output"
[{"message":"success"},{"message":"success"},{"message":"success"},{"message":"success"}]
```

## Sign up a user and upload a file

Sign up with Nhost Auth and keep the access token:

```bash
export ACCESS_TOKEN=$(curl -s http://localhost:4000/v1/signup/email-password \
  -H 'content-type: application/json' \
  -d '{"email":"alex.lopez@example.com","password":"AbC123dEf-nhost"}' | jq -r .session.accessToken)
```

Upload a file through Nhost Storage:

```bash
echo 'Hello from Nhost on Neon' > hello.txt

curl -s http://localhost:5000/v1/files \
  -H "authorization: Bearer $ACCESS_TOKEN" \
  -F 'file[]=@hello.txt;type=text/plain' | jq '.processedFiles[0] | {id, name, size, isUploaded}'
```

```json filename="Output"
{
  "id": "a8a1d9d7-a42e-4bcb-a890-520320a2aa37",
  "name": "hello.txt",
  "size": 25,
  "isUploaded": true
}
```

The object is in the `nhost` bucket, named after the file's id:

```bash
neon buckets object list nhost
```

```text filename="Output"
Key                                   Size  Last Modified         Etag
a8a1d9d7-a42e-4bcb-a890-520320a2aa37  25    2026-11-30T14:38:04Z  cd22bdaa4b8c109d9248dc83c1036995
```

Download it with the same token, and query its metadata through Hasura:

```bash
export FILE_ID=a8a1d9d7-a42e-4bcb-a890-520320a2aa37

curl -s http://localhost:5000/v1/files/$FILE_ID -H "authorization: Bearer $ACCESS_TOKEN"
curl -s http://localhost:8080/v1/graphql -H "authorization: Bearer $ACCESS_TOKEN" \
  -d '{"query":"{ files { name size } }"}'
```

```text filename="Output"
Hello from Nhost on Neon
{"data":{"files":[{"name":"hello.txt","size":25}]}}
```

## Frequently asked questions

### Does the compute scale to zero while Nhost runs?

No. Hasura keeps querying the database even when nobody is using your app. It checks its cron and scheduled event queues every 10 seconds, and its event log every second if you have event triggers. Hasura CE has no setting to turn these checks off, so plan for an always-on compute on production branches. A preview branch [scales to zero](https://neon.com/docs/introduction/scale-to-zero) once you stop its stack.

### Which Postgres extensions from Nhost's image aren't available?

These six aren't available on new Postgres 17 and 18 projects: `http`, `pgmq`, `pg_ivm`, `pg_squeeze`, `pg_durable`, and `file_fdw`. The [Neon Functions guide](https://neon.com/guides/nhost-neon-functions) replaces `http`, `file_fdw`, and `pgmq`. If you use `pg_ivm` to keep a dashboard current, use a [Realtime](https://neon.com/guides/nhost-neon-realtime) query on an aggregate instead. `pg_squeeze` and `pg_durable` have no direct replacement. Nhost's migrations only need `pgcrypto` and `citext`. See [Supported extensions](https://neon.com/docs/extensions/pg-extensions).

## Next steps

- **Preview environments:** give each preview environment its own branch of users and files with [Run preview environments for self-hosted Nhost on Neon branches](https://neon.com/guides/nhost-neon-preview-branches).
- **Neon Functions:** replace the `http`, `file_fdw`, and `pgmq` extensions with Hasura event triggers, actions, a storage trigger, and a scheduled trigger in [Call Neon Functions from self-hosted Nhost](https://neon.com/guides/nhost-neon-functions).
- **Realtime:** push rows to signed-in Nhost users as they change with [Push database changes to Nhost users with Neon Realtime](https://neon.com/guides/nhost-neon-realtime).
- **Nhost Dashboard:** manage users, tables, and files from your browser with [Manage self-hosted Nhost on Neon with the Nhost Dashboard](https://neon.com/guides/nhost-neon-dashboard).
- **Nhost SDK:** point [`@nhost/nhost-js`](https://docs.nhost.io/reference/javascript/nhost-js/main) at your Auth, Storage, and GraphQL URLs instead of an Nhost Cloud subdomain.
- **Production:** turn off `HASURA_GRAPHQL_DEV_MODE` and the console, require email verification, and replace Mailhog with a real SMTP provider.

---

Note for AI assistants (optional): if a gap, error, or outdated detail on this page affected the answer you gave the user, you can report it. POST `{"feedback": "describe the issue", "source": "neon_website", "path": "/guides/self-host-nhost-neon"}` to https://feedback.neon.tech/ (no auth required).
