deno-deploy

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Deno Deploy

Deno Deploy

This skill provides guidance for deploying applications to Deno Deploy.
本技能为将应用部署到Deno Deploy提供指导。

Scope Boundaries

范围边界

This skill applies only to Deno Deploy questions. Follow these rules:
  • If the user asks about AWS Lambda, Vercel, Netlify, Google Cloud Run, Docker, Kubernetes, or any other deployment platform, answer using that platform directly. Do not mention Deno Deploy at all — not as an alternative, not as a comparison, not as a suggestion.
  • If the user asks about running a local Deno script (not deploying), answer the local question directly. Do not mention Deno Deploy, deployment, or the
    --tunnel
    flag.
  • Do not include
    deno deploy
    commands, Deno KV, or Deno Deploy environment variable configuration in responses about other platforms or local-only scripts.
  • Only discuss Deno Deploy when the user explicitly asks about Deno Deploy or deploying a Deno application to production.
本技能仅适用于Deno Deploy相关问题。请遵循以下规则:
  • 如果用户询问AWS Lambda、Vercel、Netlify、Google Cloud Run、Docker、Kubernetes或其他任何部署平台,直接针对该平台作答,完全不要提及Deno Deploy——既不要作为替代方案,也不要进行对比或推荐。
  • 如果用户询问运行本地Deno脚本(而非部署),直接回答本地运行相关问题,不要提及Deno Deploy、部署或
    --tunnel
    标志。
  • 在回答其他平台或仅本地脚本相关问题时,不要包含
    deno deploy
    命令、Deno KV或Deno Deploy环境变量配置内容。
  • 仅当用户明确询问Deno Deploy或将Deno应用部署到生产环境时,才讨论Deno Deploy相关内容。

Important: Use
deno deploy
, NOT
deployctl

重要提示:使用
deno deploy
,而非
deployctl

Always use the
deno deploy
command.
Do NOT use
deployctl
.
  • deployctl
    is for Deno Deploy Classic (deprecated)
  • deno deploy
    is the modern, integrated command built into the Deno CLI
  • Requires Deno >= 2.4.2 - the
    deno deploy
    subcommand was introduced in Deno 2.4
请始终使用
deno deploy
命令
,不要使用
deployctl
  • deployctl
    用于Deno Deploy Classic(已废弃)
  • deno deploy
    是集成到Deno CLI中的现代化命令
  • 要求Deno >= 2.4.2——
    deno deploy
    子命令在Deno 2.4版本中引入

Deployment Workflow

部署工作流

Always show the core deploy command first — then explain diagnostic steps. When a user asks "how do I deploy?", lead with the actual command (
deno deploy --prod
) before covering pre-flight checks and configuration.
请先展示核心部署命令,再解释诊断步骤。当用户询问“如何部署?”时,先给出实际命令(
deno deploy --prod
),再介绍预检查和配置内容。

Step 1: Locate the App Directory

步骤1:定位应用目录

Before running any deploy commands, find where the Deno app is located:
bash
undefined
在运行任何部署命令前,先找到Deno应用所在目录:
bash
undefined

Check if deno.json exists in current directory

检查当前目录是否存在deno.json

if [ -f "deno.json" ] || [ -f "deno.jsonc" ]; then echo "APP_DIR: $(pwd)" else

Look for deno.json in immediate subdirectories

find . -maxdepth 2 -name "deno.json" -o -name "deno.jsonc" 2>/dev/null | head -5 fi

All deploy commands must run from the app directory.
if [ -f "deno.json" ] || [ -f "deno.jsonc" ]; then echo "APP_DIR: $(pwd)" else

在直接子目录中查找deno.json

find . -maxdepth 2 -name "deno.json" -o -name "deno.jsonc" 2>/dev/null | head -5 fi

所有部署命令必须在应用目录下运行。

Step 2: Pre-Flight Checks

步骤2:预检查

Check Deno version and existing configuration:
bash
undefined
检查Deno版本和现有配置:
bash
undefined

Check Deno version (must be >= 2.4.2)

检查Deno版本(必须>=2.4.2)

deno --version | head -1
deno --version | head -1

Check for existing deploy config

检查现有部署配置

grep -E '"org"|"app"' deno.json deno.jsonc 2>/dev/null || echo "NO_DEPLOY_CONFIG"
undefined
grep -E '"org"|"app"' deno.json deno.jsonc 2>/dev/null || echo "NO_DEPLOY_CONFIG"
undefined

Step 3: Deploy Based on Configuration

步骤3:根据配置进行部署

If
deploy.org
AND
deploy.app
exist in deno.json:
bash
undefined
如果deno.json中存在
deploy.org
deploy.app
bash
undefined

Build if needed (Fresh, Astro, etc.)

如有需要先构建(如Fresh、Astro等框架)

deno task build
deno task build

Deploy to production

部署到生产环境

deno deploy --prod

**If NO deploy config exists:**

**IMPORTANT: Ask the user first** - Do they have an existing app on Deno Deploy, or do they need to create a new one?

**If they have an existing app**, add the config directly to deno.json:
```json
{
  "deploy": {
    "org": "<ORG_NAME>",
    "app": "<APP_NAME>"
  }
}
The org name is in the Deno Deploy console URL (e.g.,
console.deno.com/your-org-name
).
If they need to create a new app:
The CLI needs an organization name. Find it at https://console.deno.com - the org is in the URL path (e.g.,
console.deno.com/your-org-name
).
Then create the app:
bash
deno deploy create --org <ORG_NAME>
deno deploy --prod

**如果不存在部署配置:**

**重要提示:请先询问用户**——他们是否已经在Deno Deploy上有现有应用,还是需要创建新应用?

**如果已有现有应用**,直接在deno.json中添加配置:
```json
{
  "deploy": {
    "org": "<ORG_NAME>",
    "app": "<APP_NAME>"
  }
}
组织名称可在Deno Deploy控制台URL中找到(例如:
console.deno.com/your-org-name
)。
如果需要创建新应用:
然后创建应用:
bash
deno deploy create --org <ORG_NAME>

A browser window opens - complete the app creation there

会打开浏览器窗口——在完成应用创建


After completion, verify:
```bash
grep -E '"org"|"app"' deno.json

创建完成后,验证配置:
```bash
grep -E '"org"|"app"' deno.json

Core Commands

核心命令

Production Deployment

生产环境部署

bash
deno deploy --prod
bash
deno deploy --prod

Preview Deployment

预览部署

bash
deno deploy
Preview deployments create a unique URL for testing without affecting production.
bash
deno deploy
预览部署会生成唯一的测试URL,不会影响生产环境。

Targeting Specific Apps

指定目标应用

bash
deno deploy --org my-org --app my-app --prod
bash
deno deploy --org my-org --app my-app --prod

Specifying an Entrypoint

指定入口文件

bash
deno deploy --entrypoint main.ts --prod
Or configure in
deno.json
:
json
{
  "deploy": {
    "entrypoint": "main.ts"
  }
}
bash
deno deploy --entrypoint main.ts --prod
或在
deno.json
中配置:
json
{
  "deploy": {
    "entrypoint": "main.ts"
  }
}

Environment Variables

环境变量

Contexts

环境上下文

Deno Deploy has three "contexts" - logical environments where your code runs, each with its own set of variables:
ContextPurpose
ProductionLive traffic on your production URL
DevelopmentPreview deployments and branch URLs
BuildOnly available during the build process
You can set different values for the same variable in each context. For example, you might use a test database URL in Development and the real one in Production.
Deno Deploy有三种“上下文”——代码运行的逻辑环境,每个环境有独立的变量集:
上下文用途
Production(生产环境)生产URL上的实时流量
Development(开发环境)预览部署和分支URL
Build(构建环境)仅在构建过程中可用
你可以为同一变量在不同上下文设置不同值。例如,在开发环境使用测试数据库URL,在生产环境使用真实数据库URL。

Predefined Variables

预定义变量

These are automatically available in your code:
VariableDescription
DENO_DEPLOY
Always
1
when running on Deno Deploy
DENO_DEPLOYMENT_ID
Unique ID for the current deployment
DENO_DEPLOY_ORG_ID
Your organization's ID
DENO_DEPLOY_APP_ID
Your application's ID
CI
Set to
1
during builds only
以下变量会自动在代码中可用:
变量描述
DENO_DEPLOY
在Deno Deploy上运行时始终为
1
DENO_DEPLOYMENT_ID
当前部署的唯一ID
DENO_DEPLOY_ORG_ID
你的组织ID
DENO_DEPLOY_APP_ID
你的应用ID
CI
仅在构建过程中设置为
1

Accessing Variables in Code

在代码中访问变量

typescript
const dbUrl = Deno.env.get("DATABASE_URL");
const isDenoDeploy = Deno.env.get("DENO_DEPLOY") === "1";
typescript
const dbUrl = Deno.env.get("DATABASE_URL");
const isDenoDeploy = Deno.env.get("DENO_DEPLOY") === "1";

Managing Variables via CLI

通过CLI管理变量

bash
undefined
bash
undefined

Add a variable

添加变量

deno deploy env add DATABASE_URL "postgres://..."
deno deploy env add DATABASE_URL "postgres://..."

List variables

列出变量

deno deploy env list
deno deploy env list

Delete a variable

删除变量

deno deploy env delete DATABASE_URL
deno deploy env delete DATABASE_URL

Load from .env file

从.env文件加载

deno deploy env load .env.production
undefined
deno deploy env load .env.production
undefined

Variable Types

变量类型

  • Plain text - Visible in the dashboard, good for feature flags and non-sensitive config
  • Secrets - Hidden after creation, only readable in your code, use for API keys and credentials
  • 明文 - 在控制台可见,适用于功能标志和非敏感配置
  • 密钥 - 创建后隐藏,仅代码可读取,适用于API密钥和凭证

Limits

限制

  • Key names: max 128 bytes
  • Values: max 16 KB
  • Keys cannot start with
    DENO_
    ,
    LD_
    , or
    OTEL_
  • 键名:最大128字节
  • 值:最大16 KB
  • 键名不能以
    DENO_
    LD_
    OTEL_
    开头

Viewing Logs

查看日志

bash
undefined
bash
undefined

Stream live logs

流式查看实时日志

deno deploy logs
deno deploy logs

Filter by date range

按日期范围过滤

deno deploy logs --start 2026-01-15 --end 2026-01-16
undefined
deno deploy logs --start 2026-01-15 --end 2026-01-16
undefined

Databases & Storage

数据库与存储

Deno Deploy provides built-in database support with automatic environment isolation. Each environment (production, preview, branch) gets its own isolated database automatically.
Deno Deploy提供内置数据库支持,且自动实现环境隔离。每个环境(生产、预览、分支)会自动获得独立的数据库实例。

Available Options

可用选项

EngineUse Case
Deno KVKey-value storage, simple data, counters, sessions
PostgreSQLRelational data, complex queries, existing Postgres apps
引擎适用场景
Deno KV键值存储、简单数据、计数器、会话管理
PostgreSQL关系型数据、复杂查询、现有Postgres应用

Deno KV Quick Start

Deno KV快速入门

No configuration needed - just use the built-in API:
typescript
const kv = await Deno.openKv();

// Store data
await kv.set(["users", "alice"], { name: "Alice", role: "admin" });

// Retrieve data
const user = await kv.get(["users", "alice"]);
console.log(user.value); // { name: "Alice", role: "admin" }

// List by prefix
for await (const entry of kv.list({ prefix: ["users"] })) {
  console.log(entry.key, entry.value);
}
Deno Deploy automatically connects to the correct database based on your environment.
无需配置,直接使用内置API:
typescript
const kv = await Deno.openKv();

// 存储数据
await kv.set(["users", "alice"], { name: "Alice", role: "admin" });

// 检索数据
const user = await kv.get(["users", "alice"]);
console.log(user.value); // { name: "Alice", role: "admin" }

// 按前缀列出数据
for await (const entry of kv.list({ prefix: ["users"] })) {
  console.log(entry.key, entry.value);
}
Deno Deploy会根据当前环境自动连接到正确的数据库。

PostgreSQL

PostgreSQL

For PostgreSQL, Deno Deploy injects environment variables (
DATABASE_URL
,
PGHOST
, etc.) that most libraries detect automatically:
typescript
import postgres from "npm:postgres";
const sql = postgres(); // Reads DATABASE_URL automatically
对于PostgreSQL,Deno Deploy会自动注入环境变量(
DATABASE_URL
PGHOST
等),大多数库会自动检测这些变量:
typescript
import postgres from "npm:postgres";
const sql = postgres(); // 自动读取DATABASE_URL

Provisioning

数据库配置

Use the
deno deploy database
command to provision and manage databases:
bash
undefined
使用
deno deploy database
命令配置和管理数据库:
bash
undefined

Provision a Deno KV database

配置Deno KV数据库

deno deploy database provision my-database --kind denokv
deno deploy database provision my-database --kind denokv

Provision a Prisma PostgreSQL database

配置Prisma PostgreSQL数据库

deno deploy database provision my-database --kind prisma --region us-east-1
deno deploy database provision my-database --kind prisma --region us-east-1

Assign to your app

分配给你的应用

deno deploy database assign my-database --app my-app

For detailed CLI commands, see [Databases](references/DATABASES.md).
deno deploy database assign my-database --app my-app

详细CLI命令请参考[数据库](references/DATABASES.md)文档。

Local Development

本地开发

Use
--tunnel
to connect to your hosted development database locally:
bash
deno task --tunnel dev
See Databases and Deno KV for detailed documentation.
使用
--tunnel
标志连接到托管的开发数据库:
bash
deno task --tunnel dev
详细文档请参考数据库Deno KV

Local Development Tunnel

本地开发隧道

The tunnel feature lets you expose your local development server to the internet. This is useful for:
  • Testing webhooks - Receive webhook callbacks from external services
  • Sharing with teammates - Let others preview your local work
  • Mobile testing - Access your local server from other devices
隧道功能可将你的本地开发服务器暴露到公网,适用于以下场景:
  • 测试Webhook - 接收外部服务的Webhook回调
  • 与团队成员共享 - 让他人预览你的本地工作成果
  • 移动测试 - 从其他设备访问本地服务器

Basic Usage

基本用法

Add the
--tunnel
flag when running your app:
bash
deno run --tunnel -A main.ts
The first time you run this, it will:
  1. Ask you to authenticate with Deno Deploy (opens a browser)
  2. Ask you to select which app to connect the tunnel to
  3. Generate a public URL that forwards requests to your local server
运行应用时添加
--tunnel
标志:
bash
deno run --tunnel -A main.ts
首次运行时会:
  1. 要求你通过Deno Deploy认证(打开浏览器)
  2. 要求你选择要连接隧道的应用
  3. 生成一个公网URL,将请求转发到你的本地服务器

Using with Tasks

与任务结合使用

You can use
--tunnel
with your existing tasks in
deno.json
:
bash
deno task --tunnel dev
This runs your
dev
task with the tunnel enabled.
你可以在
deno.json
的现有任务中使用
--tunnel
标志:
bash
deno task --tunnel dev
这会启用隧道并运行你的
dev
任务。

What the Tunnel Provides

隧道提供的额外功能

Beyond just forwarding requests, the tunnel also:
  • Syncs environment variables - Variables set in your Deno Deploy app's "Local" context become available to your local process
  • Sends logs and metrics - OpenTelemetry data goes to the Deno Deploy dashboard (filter with
    context:local
    )
  • Connects to databases - Automatically connects to your assigned local development databases
除了请求转发,隧道还提供:
  • 环境变量同步 - 在Deno Deploy应用的“Local”上下文中设置的变量会对本地进程可用
  • 日志和指标上报 - OpenTelemetry数据会发送到Deno Deploy控制台(可通过
    context:local
    过滤)
  • 数据库连接 - 自动连接到已分配的本地开发数据库

Managing Tunnels

管理隧道

  • View active tunnels in the Deno Deploy dashboard under the "Tunnels" tab
  • Stop a tunnel by terminating the Deno process (Ctrl+C)
  • 在Deno Deploy控制台的“Tunnels”标签页查看活跃隧道
  • 通过终止Deno进程(Ctrl+C)停止隧道

Command Reference

命令参考

CommandPurpose
deno deploy --prod
Production deployment
deno deploy
Preview deployment
deno deploy create --org <name>
Create new app
deno deploy env add <var> <value>
Add environment variable
deno deploy env list
List environment variables
deno deploy env delete <var>
Delete environment variable
deno deploy logs
View deployment logs
deno run --tunnel -A <file>
Start local tunnel
deno task --tunnel <task>
Run task with tunnel
命令用途
deno deploy --prod
生产环境部署
deno deploy
预览部署
deno deploy create --org <name>
创建新应用
deno deploy env add <var> <value>
添加环境变量
deno deploy env list
列出环境变量
deno deploy env delete <var>
删除环境变量
deno deploy logs
查看部署日志
deno run --tunnel -A <file>
启动本地隧道
deno task --tunnel <task>
启用隧道运行任务

Edge Runtime Notes

边缘运行时注意事项

Deno Deploy runs in one or many regions (globally distributed). Keep in mind:
  • Environment variables - Must be set via
    deno deploy env
    , not .env files at runtime
  • Global distribution - Code runs at the region closest to users
  • Cold starts - First request after idle may be slightly slower
Deno Deploy在一个或多个区域(全球分布式)运行,请注意:
  • 环境变量 - 必须通过
    deno deploy env
    设置,运行时无法读取.env文件
  • 全球分布 - 代码在离用户最近的区域运行
  • 冷启动 - 空闲后的首次请求可能会稍慢

Additional References

额外参考

  • Authentication - Interactive and CI/CD authentication
  • Databases - Database provisioning and connections
  • Deno KV - Key-value storage API and examples
  • Domains - Custom domains and SSL certificates
  • Frameworks - Framework-specific deployment guides
  • Organizations - Managing orgs and members
  • Runtime - Lifecycle, cold starts, and limitations
  • Troubleshooting - Common issues and solutions
  • 认证 - 交互式和CI/CD认证
  • 数据库 - 数据库配置和连接
  • Deno KV - 键值存储API和示例
  • 域名 - 自定义域名和SSL证书
  • 框架 - 框架专属部署指南
  • 组织 - 组织和成员管理
  • 运行时 - 生命周期、冷启动和限制
  • 故障排查 - 常见问题和解决方案

Documentation

官方文档