# Astro (/docs/guides/next/frameworks/astro)

> For the complete Prisma documentation index, see [llms.txt](https://www.prisma.io/docs/llms.txt). A markdown version of any docs page is available by appending `.md` to its URL.

Set up Prisma Next in an Astro app with create-prisma, from scaffold to rendered data, and deploy it to Prisma Compute.

Location: Guides > Next > Frameworks > Astro

## Introduction [#introduction]

This guide shows you how to use Prisma Next in an Astro site. You scaffold a project that queries users during server rendering and exposes a JSON API route, initialize the schema, see your data render, and deploy the site to [Prisma Compute](https://www.prisma.io/docs/compute).

Every command below was run end to end against a live [Prisma Postgres](https://www.prisma.io/docs/postgres) database.

## Quick start [#quick-start]

One command scaffolds the project with Prisma Next wired in:

  

#### bun

```bash
bunx create-prisma@next create my-astro-app --template astro --provider postgres
```

#### pnpm

```bash
pnpm dlx create-prisma@next create my-astro-app --template astro --provider postgres
```

#### yarn

```bash
yarn dlx create-prisma@next create my-astro-app --template astro --provider postgres
```

#### npm

```bash
npx create-prisma@next create my-astro-app --template astro --provider postgres
```

Pick Prisma Postgres at the database prompt to have a database created for you, or paste your own `DATABASE_URL`.

## Prerequisites [#prerequisites]

* [Node.js](https://nodejs.org) 24 or later
* A PostgreSQL connection string, or nothing at all: the scaffold can create the database for you

## Use with your agent [#use-with-your-agent]

Prefer to delegate this guide? Copy the prompt and hand it to your coding agent:

```text
Create a new Astro app with Prisma Next, seed it, and deploy it to Prisma Compute.

1. Scaffold: `npx create-prisma@next create my-astro-app --template astro --provider postgres --prisma-postgres --yes` (or pass `--database-url "<url>"` instead of `--prisma-postgres` if I give you a connection string).
2. In `my-astro-app`, run `npm run db:init`, then `npm run db:seed`. If seeding fails with `Cannot read properties of undefined (reading 'where')`, change `db.orm.User` to `db.orm.public.User` in `src/prisma/seed.ts` and `src/prisma/users.ts`, then rerun.
3. Start `npm run dev` in the background, wait until it reports ready, verify http://localhost:4321 lists the seeded users and `curl http://localhost:4321/api/users` returns them as JSON, then stop the dev server.
4. Prepare the deploy build: run `npm install @astrojs/node@^10`, then set `output: "server"` and `adapter: node({ mode: "standalone" })` in `astro.config.mjs`, following https://www.prisma.io/docs/guides/next/frameworks/astro.md.
5. Deploy: check `npx @prisma/cli@latest auth whoami`; if I am not signed in, stop and ask me to run `npx @prisma/cli@latest auth login`. Then run `npx @prisma/cli@latest app deploy --create-project my-astro-app --env .env --env HOST=0.0.0.0` (without HOST the live URL answers `Service not found`) and verify the live URL's /api/users endpoint with curl.

Use the installed Prisma Next skills.
```

## 1. Scaffold and enter the project [#1-scaffold-and-enter-the-project]

  

#### bun

```bash
bunx create-prisma@next create my-astro-app --template astro --provider postgres
cd my-astro-app
```

#### pnpm

```bash
pnpm dlx create-prisma@next create my-astro-app --template astro --provider postgres
cd my-astro-app
```

#### yarn

```bash
yarn dlx create-prisma@next create my-astro-app --template astro --provider postgres
cd my-astro-app
```

#### npm

```bash
npx create-prisma@next create my-astro-app --template astro --provider postgres
cd my-astro-app
```

The scaffold writes your connection string to `.env`, generates the Astro app with Prisma Next wired in, installs dependencies, and emits the contract your queries are type-checked against.

## 2. Initialize and seed the database [#2-initialize-and-seed-the-database]

  

#### bun

```bash
bun run db:init
bun run db:seed
```

#### pnpm

```bash
pnpm run db:init
pnpm run db:seed
```

#### yarn

```bash
yarn db:init
yarn db:seed
```

#### npm

```bash
npm run db:init
npm run db:seed
```

```text no-copy
"summary": "Applied 5 operation(s) across 1 space(s), database signed"
Seeded 3 users.
```

> [!NOTE]
> Seeing `Cannot read properties of undefined (reading 'where')`? The current `astro` template still generates the older unqualified query form. Update `db.orm.User` to `db.orm.public.User` in `src/prisma/seed.ts` and `src/prisma/users.ts`, then rerun `db:seed`.

`db:init` applies your schema (`src/prisma/contract.prisma`) to the database and signs it; the seed gives the first page something to show.

## 3. Run and verify [#3-run-and-verify]

  

#### bun

```bash
bun run dev
```

#### pnpm

```bash
pnpm run dev
```

#### yarn

```bash
yarn dev
```

#### npm

```bash
npm run dev
```

Open [http://localhost:4321](http://localhost:4321). The page lists the seeded users; `GET /api/users` returns them as JSON.

## Where things live [#where-things-live]

* `src/pages/index.astro`: queries users in the frontmatter and renders them
* `src/pages/api/users.ts`: a JSON API route backed by the same query
* `src/prisma/db.ts`: the Prisma Next client both import

Model access is namespace-qualified on PostgreSQL: `db.orm.public.User`. The [Prisma Next overview](https://www.prisma.io/docs/orm/next) covers the contract-first model behind it.

## 4. Deploy to Prisma Compute [#4-deploy-to-prisma-compute]

Astro is supported on [Prisma Compute](https://www.prisma.io/docs/compute), which runs the site as a Node server. That needs the Node adapter in standalone mode; without it the deploy fails at build time with `Astro build did not produce a standalone server entrypoint`. The template currently pins Astro 6, so install the matching adapter major:

  

#### bun

```bash
bun add @astrojs/node@^10
```

#### pnpm

```bash
pnpm add @astrojs/node@^10
```

#### yarn

```bash
yarn add @astrojs/node@^10
```

#### npm

```bash
npm install @astrojs/node@^10
```

Then configure the adapter in `astro.config.mjs`. Setting `output: "server"` renders the page and the API route per request, so the live site reads current data instead of freezing the build-time snapshot into static files:

```js title="astro.config.mjs"
// @ts-check
import node from "@astrojs/node";
import { prismaVitePlugin } from "@prisma-next/vite-plugin-contract-emit";
import { defineConfig } from "astro/config";

// https://astro.build/config
export default defineConfig({
  output: "server",
  adapter: node({ mode: "standalone" }),
  vite: {
    plugins: [prismaVitePlugin()],
  },
});
```

Sign in once (it opens a browser):

  

#### bun

```bash
bunx @prisma/cli@latest auth login
```

#### pnpm

```bash
pnpm dlx @prisma/cli@latest auth login
```

#### yarn

```bash
yarn dlx @prisma/cli@latest auth login
```

#### npm

```bash
npx @prisma/cli@latest auth login
```

Then deploy from the project directory. The `--env .env` flag passes your `DATABASE_URL` to the deployment, so the live site talks to the same database. The `HOST=0.0.0.0` variable is required: the standalone server binds `localhost` by default, which Compute's router cannot reach, and the live URL answers `Service not found` without it:

  

#### bun

```bash
bunx @prisma/cli@latest app deploy --env .env --env HOST=0.0.0.0
```

#### pnpm

```bash
pnpm dlx @prisma/cli@latest app deploy --env .env --env HOST=0.0.0.0
```

#### yarn

```bash
yarn dlx @prisma/cli@latest app deploy --env .env --env HOST=0.0.0.0
```

#### npm

```bash
npx @prisma/cli@latest app deploy --env .env --env HOST=0.0.0.0
```

```text no-copy
First deploy of "my-astro-app" -- promoting to production.

Build settings
  Build Command     astro build  · Astro default
  Output Directory  dist         · Astro output

Building locally...
  Built      8.3 MB
Uploading...
Deploying...
Live in 10.6s
https://<your-app>.ewr.prisma.build
```

Verify the live API route returns the seeded users:

```bash
curl https://<your-app>.ewr.prisma.build/api/users
```

The live URL's root page renders the same users server-side. The first deploy asks you to pick or create a project (pass `--create-project my-astro-app` to skip the prompt), pins the directory to it in a gitignored `.prisma/local.json`, and promotes to production. For previews per Git branch and deploy-on-push, see [Deploy your first app](https://www.prisma.io/docs/prisma-compute/deploy).

## Next steps [#next-steps]

* Change the schema in `src/prisma/contract.prisma`, then run `npm run contract:emit` and `npm run db:update`.
* [Learn the fundamentals](https://www.prisma.io/docs/orm/next/fundamentals/reading-data): filtering, sorting, pagination, and writes.
* [Read the Prisma Next overview](https://www.prisma.io/docs/orm/next) for the concepts behind contracts and typed queries.

## Related pages

- [`Elysia`](https://www.prisma.io/docs/guides/next/frameworks/elysia): Build an Elysia API on Prisma Next with the elysia template and deploy it to Prisma Compute.
- [`Hono`](https://www.prisma.io/docs/guides/next/frameworks/hono): Build a Hono API on Prisma Next with the hono template, add your own routes, and deploy it to Prisma Compute.
- [`NestJS`](https://www.prisma.io/docs/guides/next/frameworks/nestjs): Set up Prisma Next in a NestJS app with create-prisma, from scaffold to seeded API to a live deploy on Prisma Compute.
- [`Next.js`](https://www.prisma.io/docs/guides/next/frameworks/nextjs): Set up Prisma Next in a Next.js app with create-prisma, from scaffold to rendered data, and deploy it to Prisma Compute.
- [`Nuxt`](https://www.prisma.io/docs/guides/next/frameworks/nuxt): Set up Prisma Next in a Nuxt app with create-prisma, from scaffold to rendered data, and deploy it to Prisma Compute.