# Hono (/docs/guides/frameworks/hono) > 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. Build a Hono API on Prisma ORM with the hono template, add your own routes, and deploy it to Prisma Compute. Location: Guides > Frameworks > Hono ## Introduction [#introduction] In this guide, you scaffold a Hono API backed by Prisma ORM, initialize and seed a PostgreSQL database, serve data over HTTP, add your own POST route, and deploy the API to [Prisma Compute](https://www.prisma.io/docs/compute). The `hono` template generates the server for you, so most of the work is understanding the pieces and extending them. Every command, route, and response below was run end to end against a live Prisma Postgres database. ## Prerequisites [#prerequisites] - [Node.js](https://nodejs.org) 22.18 or newer on the 22 line, 24.11 or newer on the 24 line, or 26 or newer (24 recommended), or [Bun](https://bun.sh/) (this guide uses Bun for speed; npm works the same) - A PostgreSQL connection string, or nothing at all: the scaffold can create a [Prisma Postgres](https://www.prisma.io/docs/postgres) database for you To use MongoDB instead of PostgreSQL, scaffold with `--provider mongo` and follow [Create a new app with MongoDB](https://www.prisma.io/docs/prisma-orm/quickstart/mongodb) for the database steps. Neither `bun run dev:composer` (the local run in step 3) nor a deploy creates a MongoDB database for you, so export `MONGODB_URL` with your connection string before you run either. The first deploy copies the value to your project on Prisma Compute, and the deployed app reads it from there. Later deploys keep that stored value even if you export a different one. To change it, export the new connection string as `MONGODB_URL` and run `bunx prisma project env update MONGODB_URL --project my-hono-api --role production`, which copies the exported value to the project (see [`prisma project`](https://www.prisma.io/docs/cli/project)); the app gets the new value on its next deploy. If you renamed the module or deployed with `--name`, pass that name to `--project`. ## 1. Scaffold the project [#1-scaffold-the-project] ```bash bun create prisma@latest my-hono-api --template hono --provider postgres --no-deploy ``` Answer the prompts for contract authoring style, package manager, and agent skills. The template generates a Hono server in `src/index.ts` with two routes (`GET /` and `GET /users`), the Prisma ORM setup in `src/prisma/`, and package scripts for the database steps. ```bash cd my-hono-api ``` Next, set the database connection for the local steps. Use your own PostgreSQL connection string, or create a Prisma Postgres database with `npx create-db@latest`, which prints a connection string and a claim URL. Claim the database with a free Prisma account if you want to keep it. Export the variable in the shell you work in; the generated scripts read the environment variable, not `.env`: ```bash export DATABASE_URL="" ``` ## 2. Initialize the database [#2-initialize-the-database] ```bash bun run db:init ``` ```text no-copy ✔ Applied 5 operation(s) across 1 contract space App space ├─ Create table "Post" ├─ Create table "User" ├─ Add unique constraint on "User" (email) ├─ Create index "Post_authorId_idx_e47547ed" on "Post" ├─ Add foreign key "Post_authorId_fkey" on "Post" └─ marker 920a87b50729a867e21706dd0fa5c3739e273a84ed89eb2f3525633b2d6ef85c ``` If `db:init` stops with `Connection terminated unexpectedly`, a database you just created is still starting; wait a few seconds and run it again. The command is safe to repeat: when there is nothing left to do, it prints `✔ Database already matches contract across 1 contract space`. ## 3. Run the server [#3-run-the-server] ```bash bun run dev ``` The server starts on port 3000 (set `PORT` to change it). Check both routes: ```bash curl http://localhost:3000/users ``` ```json no-copy [ { "id": "1", "email": "alice@prisma.io", "username": "alice", "name": "Alice", "createdAt": "2026-11-20T10:18:03.670Z" }, { "id": "2", "email": "bob@prisma.io", "username": "bob", "name": "Bob", "createdAt": "2026-11-20T10:18:03.742Z" }, { "id": "3", "email": "carol@prisma.io", "username": "carol", "name": "Carol", "createdAt": "2026-11-20T10:18:03.749Z" } ] ``` The route handler is ordinary Hono code calling an ordinary Prisma ORM query; there is no framework adapter in between. To run the app the way Prisma Compute runs it, with no `DATABASE_URL` to set, run `bun run dev:composer` instead. It builds the app, starts a local Prisma Postgres database, applies the committed migrations to it, and prints the app's local URL. ## 4. Add a POST route [#4-add-a-post-route] Add a route that creates a user from the request body. Add this to `src/index.ts` above the `serve(...)` call: ```ts title="src/index.ts" app.post("/users", async (c) => { const body = await c.req.json<{ email: string; name?: string }>(); const { db } = await import("./prisma/db"); const user = await db.orm.public.User.create({ email: body.email, name: body.name ?? null, }); return c.json(user, 201); }); ``` Restart the server and create a user: ```bash curl -X POST http://localhost:3000/users \ -H "content-type: application/json" \ -d '{"email":"dev@prisma.io","name":"Dev"}' ``` ```json no-copy {"createdAt":"2026-11-20T10:18:03.789Z","email":"dev@prisma.io","id":4,"name":"Dev","updatedAt":"2026-11-20T10:18:03.789Z","username":null} ``` `.create(...)` returns the full inserted record, database defaults included, so the response needs no second query. ## 5. Deploy to Prisma Compute [#5-deploy-to-prisma-compute] Hono is supported on [Prisma Compute](https://www.prisma.io/docs/compute). The scaffold already declares the app for [Prisma Composer](https://www.prisma.io/docs/composer) in `module.ts` and `service.ts`, so deploying is building and handing that declaration to the CLI. Sign in once (it opens a browser): ```bash bunx prisma auth login ``` Then build and deploy from the project directory: ```bash bun run build bunx prisma deploy ``` ```text no-copy my-hono-api ├─ database postgres-database db_abc123 └─ app compute-service cps_abc123 https://xyz.ewr.prisma.build ``` The first deploy creates a project in your workspace named after your module, which is the first argument to `module()` in `module.ts` (`my-hono-api` here). The project gets its own Prisma Postgres database, declared in `module.ts`. The deploy does not use the `DATABASE_URL` from your local steps. Running `bunx prisma deploy` again updates that same project. The deploy finds the project by that name, so a deploy from any app whose module has the same name, such as two apps both scaffolded as `my-app`, goes to that same project. Give each app its own name in `module.ts`. If a project with that name exists but the CLI cannot identify or verify its stored state (one deployed by an older version of Composer, for example), the deploy stops with `HostedStateBootstrapError`: rename the module in `module.ts`, or deploy under another name with `--name ` and pass the same `--name` on every later deploy. Verify the live endpoint returns the seeded users (the deployed database seeds on its first query): ```bash curl https://xyz.ewr.prisma.build/users ``` For previews per Git branch and deploy on push, see [Deploy on push](https://www.prisma.io/docs/compute/deploy-on-push). ## Change the schema [#change-the-schema] The scaffold also writes a first migration to the `migrations/` directory. A deploy changes the hosted database only by applying the migrations in that directory, so every schema change needs a migration of its own. `migration:plan` writes each new migration as a step after the migration that `migrations/app/refs/db.json` names. That file is the `db` ref, and `db:init` creates it. If you have not run `db:init` in this checkout, for example because you only use `bun run dev:composer`, point the `db` ref at the first migration once. Pass the directory name only, without `migrations/app/` in front: `ls migrations/app` lists it, and its name ends in `_init`, such as `20261120T1011_init`. A path such as `migrations/app/20261120T1011_init` fails with `MIGRATION.REF_NOT_FOUND`. ```bash bunx prisma migration ref set db ``` After you edit `src/prisma/contract.prisma`, for example to add a `bio String?` field to `User`, run: ```bash bun run contract:emit bun run migration:plan --name add-user-bio ``` `contract:emit` updates the files your queries are type-checked against, and `migration:plan` writes the change as a new migration in `migrations/app/`. Then apply the migration to your local database, and point the `db` ref at it so that your next `migration:plan` starts from this migration. Without the ref step, the next plan would include this change a second time. If your development database is in `DATABASE_URL`, one command does both: ```bash bun run migrate --advance-ref db ``` If you use `bun run dev:composer`, restart it: it applies new migrations when it starts. It does not update the `db` ref, so once it is running, set the ref yourself. Pass the last part of the path that `migration:plan` printed on its `app space:` line: for `migrations/app/20261120T1124_add_user_bio`, that is `bunx prisma migration ref set db 20261120T1124_add_user_bio`. ```bash bunx prisma migration ref set db ``` Commit the `migrations/` directory with your change, including `migrations/app/refs/db.json`, then deploy again with `bun run build` and `bunx prisma deploy`. The deploy applies the new migration to the hosted database before it starts the new version of your app. If you skip `migration:plan`, the deploy stops with `MIGRATION_PATH_NOT_FOUND`, because no migration in `migrations/` leads to your new schema. If you changed your database with `db:update`, which makes the database match the schema without writing a migration, `migration:plan` stops with `MIGRATION.HASH_NOT_IN_GRAPH`. Pass the newest migration with `--from`: it is the first migration name in the graph that `bunx prisma migration list` prints, such as `20261120T1124_add_user_bio`. Then apply the migration as above: ```bash bun run migration:plan --from --name add-user-bio ``` ## Common gotchas [#common-gotchas] > [!WARNING] > In a long-running server, don't call `db.close()` in route handlers; the client's connection pool is shared across requests. Close it only on process shutdown. ## Use with your agent [#use-with-your-agent] To delegate this guide to your coding agent, copy the prompt below and hand it over: ```text Create a new Hono API with Prisma ORM, seed it, and deploy it to Prisma Compute. 1. Scaffold: `bun create prisma@latest my-hono-api --template hono --provider postgres --yes`. The scaffold installs the Prisma agent skills; use them. Get a database connection string: use the one I give you, or create a Prisma Postgres database with `npx create-db@latest` and show me the claim URL it prints. Export it as `DATABASE_URL` in the shell; the generated scripts read the environment variable, not `.env`. 2. In `my-hono-api`, run `bun run db:init` with `DATABASE_URL` exported. The app seeds sample users on its first query, from `src/prisma/seed.ts`; there is no seed command to run. 3. Start `bun run dev` in the background, wait until it reports ready, verify `curl http://localhost:3000/users` returns the seeded users, then stop the dev server. 4. Add a POST /users route that creates a user from the request body, following https://www.prisma.io/docs/guides/frameworks/hono.md, restart the dev server, and verify it with curl. 5. Deploy: check `bunx prisma auth whoami`; if I am not signed in, stop and ask me to run `bunx prisma auth login`. Then run `bun run build` followed by `bunx prisma deploy` and verify the live URL's /users endpoint. The deployed app provisions and seeds its own Prisma Postgres database; do not pass the local DATABASE_URL. If the deploy fails with `HostedStateBootstrapError`, a project with the module's name exists in my workspace but its hosted state cannot be verified; re-run the deploy with `--name `. ``` The scaffold installs the [Prisma ORM skills](https://www.prisma.io/docs/ai/tools/skills#available-skills-for-prisma-8) for Claude Code, Cursor, Codex, and Devin when you answer yes to its agent skills prompt. To install them later, run [`bunx prisma@latest init`](https://www.prisma.io/docs/cli/init) in the project. Prompts you can give your agent after this guide: - "Using the prisma-8 skill, add GET /users/:id that returns one user or a 404." - "Expose GET /users/:id/posts using the Post model that ships with the starter contract." - "Add a POST /users/:id/posts route that creates a user's first post and updates their name in one [transaction](https://www.prisma.io/docs/orm/fundamentals/transactions)." ## Next steps [#next-steps] - [Learn the fundamentals](https://www.prisma.io/docs/orm/fundamentals/reading-data): filtering, sorting, pagination, and writes. - [Read the Prisma ORM overview](https://www.prisma.io/docs/orm) for the concepts behind contracts and typed queries. ## Related pages - [Astro](https://www.prisma.io/docs/guides/frameworks/astro): Set up Prisma ORM in an Astro app with create-prisma, from scaffold to rendered data, and deploy it to Prisma Compute. - [Elysia](https://www.prisma.io/docs/guides/frameworks/elysia): Build an Elysia API on Prisma ORM with the elysia template and deploy it to Prisma Compute. - [NestJS](https://www.prisma.io/docs/guides/frameworks/nestjs): Set up Prisma ORM 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/frameworks/nextjs): Set up Prisma ORM 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/frameworks/nuxt): Set up Prisma ORM in a Nuxt app with create-prisma, from scaffold to rendered data, and deploy it to Prisma Compute.