# Deno

The `deno` host deploys your app to Deno Deploy. Nitro builds the server at
`.output/server/index.mjs`. Definitions, KV Stores, and Runtime Helpers stay
portable. Deno code stays in generated output and driver configuration.

## Deno boundaries

| Concern | ViteHub boundary |
| --- | --- |
| Agent chat and webhook routes | The Nitro server mounts the standard chat dispatcher and webhook route. Route-enabled Channels pick which Agents answer chat requests. |
| Static cron schedules | `schedule: true` writes `.output/schedule/deno-cron.mjs`, which registers each Schedule with `Deno.cron`. The generated `.output/main.ts` loads it before the server. |
| Lightweight state | KV defaults to `driver: 'deno-kv'` and native `Deno.openKv()`. |
| Not available | Blob without an explicit store, Queue, Rate Limit, and Sandbox fail the build. |
| Deployment | Deno Deploy owns environment variables, permissions, logs, and rollout. |

The Agent option `runtime: 'deno'` writes a separate
`.vitehub/agent/deno-server.ts`. The `deno` host rejects it, because that
server is outside the deployed Nitro entry.

## Configure the host

Select the `deno` host. This example also turns on Schedule, so install the
Schedule package first.

```bash [Terminal]
pnpm add @vite-hub/schedule
```

### Nuxt

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  modules: ['vite-hub/nuxt'],
  vitehub: {
    host: 'deno',
    agent: true,
    console: false,
    schedule: true,
    workflow: false,
    kv: {
      driver: 'deno-kv',
    },
  },
})
```

### Nitro

```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { nitro } from 'nitro/vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({
      host: 'deno',
      agent: true,
      console: false,
      schedule: true,
      workflow: false,
      kv: {
        driver: 'deno-kv',
      },
    }),
    nitro(),
  ],
})
```

### Vite

```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({
      host: 'deno',
      agent: true,
      console: false,
      schedule: true,
      workflow: false,
      kv: {
        driver: 'deno-kv',
      },
    }),
  ],
})
```

The generated Nitro server imports your Agent Definitions and mounts the webhook route pattern and the standard `/api/_vitehub/agents/[agent]/chat` dispatcher.
With Schedules, the build writes `.output/main.ts`. It registers the cron output, then starts the server. To run your own code first, add a `main.ts` to the project root. The build bundles it into `.output/main.ts` in place of the generated file. It must import both files:

```ts [main.ts]
await import(new URL('./schedule/deno-cron.mjs', import.meta.url).href)
await import(new URL('./server/index.mjs', import.meta.url).href)
```

## Generated output

A production build puts the Deno server, the `main.ts` entrypoint, and Schedule output under `.output`. Without Schedules, the entrypoint is `.output/server/index.mjs`.

```bash [Terminal]
pnpm build
test -f .output/server/index.mjs
test -f .output/main.ts
find .output -maxdepth 4 -type f | sort
```

Pin the server to port `8000` so shell variables cannot change the address.

```bash [Terminal]
HOST=0.0.0.0 PORT=8000 NITRO_HOST=0.0.0.0 NITRO_PORT=8000 deno run --unstable-cron --allow-env --allow-read=.output --allow-net .output/main.ts
```

A route that uses `driver: 'deno-kv'` also needs Deno KV support:

```bash [Terminal]
HOST=0.0.0.0 PORT=8000 NITRO_HOST=0.0.0.0 NITRO_PORT=8000 deno run --unstable-cron --unstable-kv --allow-env --allow-read=.output --allow-net .output/main.ts
```

For one `support` Agent with the default chat route, the generated route accepts this request. The Agent must attach a route-enabled `webChat()` Channel. The dispatcher cannot reach Agents without one.

```bash [Terminal]
curl -X POST http://127.0.0.1:8000/api/_vitehub/agents/support/chat \
  -H 'content-type: application/json' \
  -d '{"id":"local","messages":[{"id":"user-1","role":"user","parts":[{"type":"text","text":"ping"}]}]}'
```

## Production notes

When `.output/main.ts` exists, Deno Deploy uses it as the entrypoint. It registers the static schedules, then starts `.output/server/index.mjs`.
Import generated files only in this entrypoint. Agent Definitions and other app code use Runtime Helpers and stable ViteHub imports.

- Put model keys and other Runtime Env in Deno environment variables.
- With Deno KV, check that the deployed runtime can call `Deno.openKv()`. Set an explicit KV Store when local development must not share production state.
- On Deno Deploy, create a KV database and assign it to the app before the first deploy that uses it. ViteHub Provision does not create it; see [Resources without provisioning](https://vitehub.dev/docs/development/provisioning#resources-without-provisioning).

## Next steps

- See [Runtime and host support](https://vitehub.dev/docs/frameworks-hosts/support-matrix) for host limits.
- See [Provider output](https://vitehub.dev/docs/reference/provider-output) for generated files.
- See [Generated files](https://vitehub.dev/docs/development/generated-files) to inspect `.vitehub/**`.
- See [Config options](https://vitehub.dev/docs/reference/config-options) for Agent `runtime` and KV `driver`.

<!-- vitehub-docs:section-links -->
## In this section

- [Choose a target](https://vitehub.dev/raw/docs/frameworks-hosts.md)
- [Frameworks](https://vitehub.dev/raw/docs/frameworks-hosts/nuxt.md)
- Deployment hosts
  - [Cloudflare](https://vitehub.dev/raw/docs/frameworks-hosts/cloudflare.md)
  - [Vercel](https://vitehub.dev/raw/docs/frameworks-hosts/vercel.md)
  - [Netlify](https://vitehub.dev/raw/docs/frameworks-hosts/netlify.md)
  - [Deno](https://vitehub.dev/raw/docs/frameworks-hosts/deno.md) (this page)
  - [Node and self-hosted](https://vitehub.dev/raw/docs/frameworks-hosts/node-self-hosted.md)
  - [Production deployment](https://vitehub.dev/raw/docs/frameworks-hosts/production.md)
  - [Canonical redirects](https://vitehub.dev/raw/docs/frameworks-hosts/redirects.md)
  - [Sitemap and robots.txt](https://vitehub.dev/raw/docs/frameworks-hosts/sitemap.md)

Next: [Node and self-hosted](https://vitehub.dev/raw/docs/frameworks-hosts/node-self-hosted.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
