|
| 1 | +--- |
| 2 | +title: Deno |
| 3 | +description: Run a minimal Prisma 8 and PostgreSQL app on Deno. |
| 4 | +url: /guides/v8/runtimes/deno |
| 5 | +metaTitle: How to use Prisma 8 with Deno |
| 6 | +metaDescription: Scaffold a Prisma 8 project for Deno, initialize Prisma Postgres, and run the generated typed query end to end. |
| 7 | +--- |
| 8 | + |
| 9 | +## Introduction |
| 10 | + |
| 11 | +In this guide, you scaffold a minimal Prisma 8 app for Deno, initialize a PostgreSQL database, and run the generated typed query. The app uses Deno-native tasks and explicit `.ts` extensions for relative imports. |
| 12 | + |
| 13 | +Every command below was run end to end against a live Prisma Postgres database. |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +- [Deno](https://deno.com/) 2.0 or later (`deno --version`) |
| 18 | + |
| 19 | +## Use with your agent |
| 20 | + |
| 21 | +Prefer to delegate this guide? Copy this prompt and hand it to your coding agent: |
| 22 | + |
| 23 | +<AgentPrompt> |
| 24 | + |
| 25 | +```text |
| 26 | +Create and verify a minimal Prisma 8 app on Deno. |
| 27 | +
|
| 28 | +1. Run `deno run -A npm:create-prisma@latest my-deno-app --template minimal --provider postgres --package-manager deno --no-deploy --yes`. |
| 29 | +2. Enter `my-deno-app`. Run `deno run -A npm:create-db@latest --env .env --ttl 24h` and show me the claim URL so I can keep the temporary database. |
| 30 | +3. Run `deno task db:init`, then start `deno task dev` in the background. |
| 31 | +4. Request `http://localhost:3000` and verify that it returns Alice, Bob, and Carol. The first request seeds these users automatically; do not add or run a separate seed command. |
| 32 | +5. Do not deploy to Prisma Compute because it does not support Deno. |
| 33 | +
|
| 34 | +Use the generated tasks instead of invoking a Prisma CLI package directly. |
| 35 | +``` |
| 36 | + |
| 37 | +</AgentPrompt> |
| 38 | + |
| 39 | +## 1. Scaffold the project |
| 40 | + |
| 41 | +Run `create-prisma` through Deno and select the minimal PostgreSQL template: |
| 42 | + |
| 43 | +```bash |
| 44 | +deno run -A npm:create-prisma@latest my-deno-app --template minimal --provider postgres --package-manager deno --no-deploy |
| 45 | +``` |
| 46 | + |
| 47 | +The command creates the app, installs its npm dependencies through Deno, and emits the Prisma contract artifacts. Deno support is currently limited to the minimal PostgreSQL template. |
| 48 | + |
| 49 | +```bash |
| 50 | +cd my-deno-app |
| 51 | +``` |
| 52 | + |
| 53 | +The generated project includes: |
| 54 | + |
| 55 | +- `deno.json` with npm compatibility enabled |
| 56 | +- Deno-native `dev`, `build`, and Prisma tasks in `package.json` |
| 57 | +- explicit `.ts` extensions on relative imports |
| 58 | +- no Composer or Prisma Compute deployment files |
| 59 | + |
| 60 | +## 2. Create and initialize the database |
| 61 | + |
| 62 | +Create a temporary Prisma Postgres database and write its connection string to `.env`: |
| 63 | + |
| 64 | +```bash |
| 65 | +deno run -A npm:create-db@latest --env .env --ttl 24h |
| 66 | +``` |
| 67 | + |
| 68 | +The command prints a claim URL. Open it within 24 hours to keep the database, or replace `DATABASE_URL` in `.env` with your own PostgreSQL connection string. |
| 69 | + |
| 70 | +Apply the starter contract and sign the database: |
| 71 | + |
| 72 | +```bash |
| 73 | +deno task db:init |
| 74 | +``` |
| 75 | + |
| 76 | +## 3. Run the app |
| 77 | + |
| 78 | +Start the generated HTTP server: |
| 79 | + |
| 80 | +```bash |
| 81 | +deno task dev |
| 82 | +``` |
| 83 | + |
| 84 | +Then request it from another terminal: |
| 85 | + |
| 86 | +```bash |
| 87 | +curl http://localhost:3000 |
| 88 | +``` |
| 89 | + |
| 90 | +The response contains the starter users: |
| 91 | + |
| 92 | +```json no-copy |
| 93 | +{ |
| 94 | + "users": [ |
| 95 | + { "email": "alice@prisma.io", "name": "Alice" }, |
| 96 | + { "email": "bob@prisma.io", "name": "Bob" }, |
| 97 | + { "email": "carol@prisma.io", "name": "Carol" } |
| 98 | + ] |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +The first request runs `src/prisma/seed.ts` through the generated query helper. Seeding is idempotent, so later requests read the same rows without creating duplicates. There is no separate seed command. |
| 103 | + |
| 104 | +## 4. Understand the generated query |
| 105 | + |
| 106 | +The generated `src/prisma/users.ts` connects the database, seeds on the first query, and reads from the PostgreSQL `public` namespace: |
| 107 | + |
| 108 | +```ts title="src/prisma/users.ts" |
| 109 | +import { db } from "./db.ts"; |
| 110 | +import { seed } from "./seed.ts"; |
| 111 | + |
| 112 | +export async function listUsers(limit = 10) { |
| 113 | + await seed(); |
| 114 | + |
| 115 | + const users = await db.orm.public.User |
| 116 | + .select("id", "email", "username", "name", "createdAt") |
| 117 | + .take(limit) |
| 118 | + .all(); |
| 119 | + |
| 120 | + return users.map((user) => ({ |
| 121 | + id: String(user.id), |
| 122 | + email: user.email, |
| 123 | + username: user.username ?? null, |
| 124 | + name: user.name ?? null, |
| 125 | + createdAt: user.createdAt, |
| 126 | + })); |
| 127 | +} |
| 128 | +``` |
| 129 | + |
| 130 | +Deno requires the `.ts` extension on these relative imports. The generated files already include it. |
| 131 | + |
| 132 | +After changing `src/prisma/contract.prisma`, regenerate the typed artifacts and update the database: |
| 133 | + |
| 134 | +```bash |
| 135 | +deno task contract:emit |
| 136 | +deno task db:update |
| 137 | +``` |
| 138 | + |
| 139 | +## Current limitations |
| 140 | + |
| 141 | +- Prisma Compute does not support Deno deployments yet. |
| 142 | +- The generated ORM tasks currently use the Deno-compatible Prisma 8 ORM CLI entry point. The consolidated `npm:prisma@next` CLI still loads Node-only credential storage under Deno, so use the generated tasks rather than invoking a CLI package directly. |
| 143 | +- The generated commands use `-A` for the filesystem, environment, and network permissions required during setup and local development. You can replace it with a narrower allow list for your application after setup. |
| 144 | + |
| 145 | +## Next steps |
| 146 | + |
| 147 | +- [Learn the fundamentals](/orm/v8/fundamentals/reading-data): filtering, sorting, pagination, and writes. |
| 148 | +- [Read the Prisma 8 overview](/orm/v8) for contracts, typed queries, and migrations. |
| 149 | +- [Use the Bun guide](/guides/v8/runtimes/bun) if you also target Bun. |
0 commit comments