deno-deploy
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDeno 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 flag.
--tunnel - Do not include commands, Deno KV, or Deno Deploy environment variable configuration in responses about other platforms or local-only scripts.
deno deploy - 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 KV或Deno Deploy环境变量配置内容。
deno deploy - 仅当用户明确询问Deno Deploy或将Deno应用部署到生产环境时,才讨论Deno Deploy相关内容。
Important: Use deno deploy
, NOT deployctl
deno deploydeployctl重要提示:使用deno deploy
,而非deployctl
deno deploydeployctlAlways use the command. Do NOT use .
deno deploydeployctl- is for Deno Deploy Classic (deprecated)
deployctl - is the modern, integrated command built into the Deno CLI
deno deploy - Requires Deno >= 2.4.2 - the subcommand was introduced in Deno 2.4
deno deploy
请始终使用命令,不要使用。
deno deploydeployctl- 用于Deno Deploy Classic(已废弃)
deployctl - 是集成到Deno CLI中的现代化命令
deno deploy - 要求Deno >= 2.4.2——子命令在Deno 2.4版本中引入
deno deploy
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 () before covering pre-flight checks and configuration.
deno deploy --prod请先展示核心部署命令,再解释诊断步骤。当用户询问“如何部署?”时,先给出实际命令(),再介绍预检查和配置内容。
deno deploy --prodStep 1: Locate the App Directory
步骤1:定位应用目录
Before running any deploy commands, find where the Deno app is located:
bash
undefined在运行任何部署命令前,先找到Deno应用所在目录:
bash
undefinedCheck 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
undefinedCheck 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"
undefinedgrep -E '"org"|"app"' deno.json deno.jsonc 2>/dev/null || echo "NO_DEPLOY_CONFIG"
undefinedStep 3: Deploy Based on Configuration
步骤3:根据配置进行部署
If AND exist in deno.json:
deploy.orgdeploy.appbash
undefined如果deno.json中存在和:
deploy.orgdeploy.appbash
undefinedBuild 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-nameIf 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-nameThen 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.jsonCore Commands
核心命令
Production Deployment
生产环境部署
bash
deno deploy --prodbash
deno deploy --prodPreview Deployment
预览部署
bash
deno deployPreview 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 --prodbash
deno deploy --org my-org --app my-app --prodSpecifying an Entrypoint
指定入口文件
bash
deno deploy --entrypoint main.ts --prodOr configure in :
deno.jsonjson
{
"deploy": {
"entrypoint": "main.ts"
}
}bash
deno deploy --entrypoint main.ts --prod或在中配置:
deno.jsonjson
{
"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:
| Context | Purpose |
|---|---|
| Production | Live traffic on your production URL |
| Development | Preview deployments and branch URLs |
| Build | Only 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:
| Variable | Description |
|---|---|
| Always |
| Unique ID for the current deployment |
| Your organization's ID |
| Your application's ID |
| Set to |
以下变量会自动在代码中可用:
| 变量 | 描述 |
|---|---|
| 在Deno Deploy上运行时始终为 |
| 当前部署的唯一ID |
| 你的组织ID |
| 你的应用ID |
| 仅在构建过程中设置为 |
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
undefinedbash
undefinedAdd 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
undefineddeno deploy env load .env.production
undefinedVariable 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_, orLD_OTEL_
- 键名:最大128字节
- 值:最大16 KB
- 键名不能以、
DENO_或LD_开头OTEL_
Viewing Logs
查看日志
bash
undefinedbash
undefinedStream live logs
流式查看实时日志
deno deploy logs
deno deploy logs
Filter by date range
按日期范围过滤
deno deploy logs --start 2026-01-15 --end 2026-01-16
undefineddeno deploy logs --start 2026-01-15 --end 2026-01-16
undefinedDatabases & 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
可用选项
| Engine | Use Case |
|---|---|
| Deno KV | Key-value storage, simple data, counters, sessions |
| PostgreSQL | Relational 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 (, , etc.) that most libraries detect automatically:
DATABASE_URLPGHOSTtypescript
import postgres from "npm:postgres";
const sql = postgres(); // Reads DATABASE_URL automatically对于PostgreSQL,Deno Deploy会自动注入环境变量(、等),大多数库会自动检测这些变量:
DATABASE_URLPGHOSTtypescript
import postgres from "npm:postgres";
const sql = postgres(); // 自动读取DATABASE_URLProvisioning
数据库配置
Use the command to provision and manage databases:
deno deploy databasebash
undefined使用命令配置和管理数据库:
deno deploy databasebash
undefinedProvision 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 to connect to your hosted development database locally:
--tunnelbash
deno task --tunnel devSee Databases and Deno KV for detailed documentation.
使用标志连接到托管的开发数据库:
--tunnelbash
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 flag when running your app:
--tunnelbash
deno run --tunnel -A main.tsThe first time you run this, it will:
- Ask you to authenticate with Deno Deploy (opens a browser)
- Ask you to select which app to connect the tunnel to
- Generate a public URL that forwards requests to your local server
运行应用时添加标志:
--tunnelbash
deno run --tunnel -A main.ts首次运行时会:
- 要求你通过Deno Deploy认证(打开浏览器)
- 要求你选择要连接隧道的应用
- 生成一个公网URL,将请求转发到你的本地服务器
Using with Tasks
与任务结合使用
You can use with your existing tasks in :
--tunneldeno.jsonbash
deno task --tunnel devThis runs your task with the tunnel enabled.
dev你可以在的现有任务中使用标志:
deno.json--tunnelbash
deno task --tunnel dev这会启用隧道并运行你的任务。
devWhat 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
命令参考
| Command | Purpose |
|---|---|
| Production deployment |
| Preview deployment |
| Create new app |
| Add environment variable |
| List environment variables |
| Delete environment variable |
| View deployment logs |
| Start local tunnel |
| Run task with tunnel |
| 命令 | 用途 |
|---|---|
| 生产环境部署 |
| 预览部署 |
| 创建新应用 |
| 添加环境变量 |
| 列出环境变量 |
| 删除环境变量 |
| 查看部署日志 |
| 启动本地隧道 |
| 启用隧道运行任务 |
Edge Runtime Notes
边缘运行时注意事项
Deno Deploy runs in one or many regions (globally distributed). Keep in mind:
- Environment variables - Must be set via , not .env files at runtime
deno deploy env - Global distribution - Code runs at the region closest to users
- Cold starts - First request after idle may be slightly slower
Deno Deploy在一个或多个区域(全球分布式)运行,请注意:
- 环境变量 - 必须通过设置,运行时无法读取.env文件
deno deploy 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
官方文档
- Official docs: https://docs.deno.com/deploy/
- CLI reference: https://docs.deno.com/runtime/reference/cli/deploy/
- Databases: https://docs.deno.com/deploy/reference/databases/
- Deno KV: https://docs.deno.com/deploy/reference/deno_kv/
- Domains: https://docs.deno.com/deploy/reference/domains/
- Environment variables & contexts: https://docs.deno.com/deploy/reference/env_vars_and_contexts/
- Organizations: https://docs.deno.com/deploy/reference/organizations/
- Runtime: https://docs.deno.com/deploy/reference/runtime/
- Tunnel: https://docs.deno.com/deploy/reference/tunnel/
- 官方文档:https://docs.deno.com/deploy/
- CLI参考:https://docs.deno.com/runtime/reference/cli/deploy/
- 数据库:https://docs.deno.com/deploy/reference/databases/
- Deno KV:https://docs.deno.com/deploy/reference/deno_kv/
- 域名:https://docs.deno.com/deploy/reference/domains/
- 环境变量与上下文:https://docs.deno.com/deploy/reference/env_vars_and_contexts/
- 组织:https://docs.deno.com/deploy/reference/organizations/
- 运行时:https://docs.deno.com/deploy/reference/runtime/
- 隧道:https://docs.deno.com/deploy/reference/tunnel/