0Pricing
Edge Computing with Cloudflare Workers & Deno · 课时

Deno Deploy 与 CLI

利用 Deno Deploy 将 Deno 应用直接部署到边缘,并使用高级 CLI 功能

Deno Deploy 与 CLI 是 CoddyKit 上的免费 Edge Computing with Cloudflare Workers & Deno 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Edge Computing with Cloudflare Workers & Deno 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Edge Computing with Cloudflare Workers & Deno 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Welcome to Deno Deploy

In this lesson, we'll dive into Deno Deploy, a powerful platform designed for deploying Deno applications directly to the edge. It's built by the Deno team itself!

Think of it as a serverless environment optimized specifically for Deno, offering incredible speed and global reach without complex setup.

Deno Deploy's Core Philosophy

Deno Deploy simplifies edge deployment by letting you run your Deno code without complex build steps or configuration. It focuses on:

  • Simplicity: Deploy with a single command.
  • Speed: Your applications run on a globally distributed network.
  • Deno-Native: Your Deno code runs as-is, no transpilation needed.

This means less overhead and faster development cycles compared to other edge platforms.

Getting Started with Deno Deploy CLI

To deploy your Deno application, you'll primarily use the deno deploy command-line interface (CLI). First, ensure you have Deno installed.

You'll also need a Deno Deploy account to link your deployments. It's free to get started!

The CLI handles authentication and project management for you.

Your First Edge Function

Let's create a simple Deno HTTP server. Save this code as main.ts. It will respond with 'Hello from Deno Deploy!' when accessed.

This is a complete, runnable Deno program, ready for the edge:

import { serve } from "https://deno.land/std@0.210.0/http/server.ts";

const handler = (_req: Request): Response => {
  return new Response("Hello from Deno Deploy!");
};

serve(handler, { port: 8000 });
console.log("Server running on http://localhost:8000/");

Deploying Your Application

Once you have your Deno code (like main.ts), deploying it is straightforward. You'll use the deno deploy command.

You can create a project via the Deno Deploy dashboard or let the CLI create one for you.

Example deployment command:

deno deploy --project=<your-project-name> main.ts

Monitoring with Deno Deploy CLI

After deployment, you'll want to check its status and view logs. The Deno Deploy CLI provides convenient commands for this:

  • deno deploy status [project-name]: Shows information about your project's deployments, including URLs and status.
  • deno deploy logs [project-name]: Streams real-time logs from your running application, vital for debugging.

These tools are crucial for maintaining and debugging your edge functions.

Environment Variables & Secrets

Edge applications often need configuration or secrets (like API keys). Deno Deploy supports environment variables for this.

You define these variables in your project's settings on the Deno Deploy dashboard. They are securely injected into your application's runtime.

In your Deno code, you access them using Deno.env.get("VAR_NAME").

Using Environment Variables in Code

Let's update our Deno server to use an environment variable. Imagine we set GREETING_MESSAGE in the Deno Deploy dashboard.

This makes your application more flexible and secure by separating configuration from code:

import { serve } from "https://deno.land/std@0.210.0/http/server.ts";

const greeting = Deno.env.get("GREETING_MESSAGE") || "Hello from default!";

const handler = (_req: Request): Response => {
  return new Response(greeting);
};

serve(handler, { port: 8000 });
console.log("Server running on http://localhost:8000/");

Advanced Deployment Options

Deno Deploy offers more advanced features to enhance your workflow and application:

  • Git Integration: Connect your GitHub repository for automatic deployments on every push.
  • Custom Domains: Map your own domain names to your deployed applications for brand consistency.
  • Production Flag: Use --production with the CLI for optimized production deployments.

These features streamline your CI/CD pipeline and improve the user experience.

Deno Deploy CLI Question

Which of the following commands would you use to view real-time logs from your deployed Deno Deploy application?

Recap: Deno Deploy & CLI

You've learned about Deno Deploy, a Deno-native platform for edge deployment. We covered:

  • Its core benefits: simplicity, speed, and Deno-native execution.
  • Using the deno deploy CLI for simple and advanced deployments.
  • Managing environment variables for secure configuration.
  • Monitoring your applications with deno deploy status and logs.

Deno Deploy offers a powerful, streamlined way to bring your Deno applications directly to the edge!

常见问题解答

「Deno Deploy 与 CLI」课时是免费的吗?

是的 — 「Deno Deploy 与 CLI」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Edge Computing with Cloudflare Workers & Deno 课程的其余内容,请升级到 CoddyKit PRO。 Edge Computing with Cloudflare Workers & Deno 课程共包含 4 节课。

「Deno Deploy 与 CLI」这节课中我会学到什么?

利用 Deno Deploy 将 Deno 应用直接部署到边缘,并使用高级 CLI 功能 你通过在浏览器中直接运行的动手代码来练习 Edge Computing with Cloudflare Workers & Deno,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Edge Computing with Cloudflare Workers & Deno 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Edge Computing with Cloudflare Workers & Deno 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。

「Deno Deploy 与 CLI」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Edge Computing with Cloudflare Workers & Deno 课中编写并运行代码吗?

能。每节 Edge Computing with Cloudflare Workers & Deno 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. Deno Deploy 与 CLI
  2. 自定义运行时环境
  3. 边缘测试与 CI/CD
  4. 蓝绿部署与渐进式发布
← 返回 Edge Computing with Cloudflare Workers & Deno