Cloudflare Workers에서 Deno 사용하기
Deno 모듈을 Cloudflare Workers로 배포하기 위해 트랜스파일하거나 번들링하는 방법을 알아봅니다.
Cloudflare Workers에서 Deno 사용하기은(는) CoddyKit의 무료 Edge Computing with Cloudflare Workers & Deno 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Edge Computing with Cloudflare Workers & Deno 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Edge Computing with Cloudflare Workers & Deno 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Deno on Cloudflare Workers
Welcome! In this lesson, we'll explore how to bring the power of Deno to Cloudflare Workers. This integration lets you leverage Deno's modern runtime features while benefiting from Workers' global edge network.
You'll learn how to prepare your Deno code so it can run seamlessly on Cloudflare's serverless platform.
Edge Runtime Differences
Cloudflare Workers run in a V8 JavaScript engine environment. While Deno also uses V8, it adds its own APIs (like Deno.readTextFile, Deno.serve) and a secure permission model.
These Deno-specific APIs aren't directly available in the standard Worker runtime. So, how do we make Deno code compatible?
Solution 1: Transpilation
The first key step is transpilation. This is the process of converting source code from one language or version to another while maintaining its functionality.
- TypeScript to JavaScript: Deno often uses TypeScript. Workers need plain JavaScript. Transpilation converts your
.tsfiles to.js. - Modern JS to Older JS: Sometimes, newer JavaScript features might be transpiled down for broader compatibility.
TypeScript Transpilation
Imagine you have a Deno utility written in TypeScript:
// my_util.ts
export function calculateSum(a: number, b: number): number {
return a + b;
}During transpilation, this becomes standard JavaScript, removing type annotations:
// my_util.js (after transpilation)
export function calculateSum(a, b) {
return a + b;
}This JavaScript is now understood by the Worker runtime.
Solution 2: Bundling
The second crucial step is bundling. This combines multiple JavaScript modules and their dependencies into a single, optimized JavaScript file.
- Single File: Workers are often deployed as a single JavaScript file.
- Performance: Bundling reduces the number of files the runtime needs to load, improving startup time.
- Dependency Management: It resolves and includes all necessary code from imported modules.
Deno Utility Function
Here's a simple Deno function. In a real project, this might be in its own module (e.g., utils.ts) and imported. For now, let's see it run directly:
function getGreeting(name: string): string {
return `Hello, ${name}! Welcome to the Edge!`;
}
console.log(getGreeting("CoddyKit Learner"));The Bundling Process
Imagine we have our getGreeting function from the previous scene, perhaps in a file called src/utils.ts, and our main Worker logic in src/worker.ts that imports it.
// src/worker.ts
import { getGreeting } from './utils.ts';
// ... Worker logic ...A bundler will take src/worker.ts as an entry point, resolve the import, transpile any TypeScript, and combine everything into one JavaScript file.
Deno-Powered Worker Output
After bundling, your Deno code, now transpiled to JavaScript and combined into a single file, looks like a standard Cloudflare Worker. This is the file you'd deploy.
Here's a simplified example of what the output might resemble, including our greeting logic:
// worker.js (bundled output)
function getGreeting(name) {
return `Hello, ${name}! Welcome to the Edge!`;
}
export default {
async fetch(request) {
const url = new URL(request.url);
const name = url.searchParams.get("name") || "Guest";
const message = getGreeting(name);
return new Response(message, {
headers: { "content-type": "text/plain" },
});
},
};Deployment with Wrangler
Once your Deno code is transpiled and bundled into a single JavaScript file (e.g., worker.js), you can deploy it using Cloudflare's Wrangler CLI, just like any other Worker.
- Wrangler handles uploading this bundled file to Cloudflare.
- The Cloudflare edge network then runs your JavaScript, effectively executing your Deno-originating logic.
The developer experience is Deno-first, but the deployment target is a standard Worker.
Quick Check
When deploying Deno code to Cloudflare Workers, which two processes are essential to make your Deno modules compatible with the Worker runtime?
Recap: Deno at the Edge
Great job! You've learned how Deno modules can be deployed as Cloudflare Workers.
- Cloudflare Workers run JavaScript, so Deno code needs transpilation (e.g., TypeScript to JavaScript).
- For efficient deployment, multiple Deno modules are combined into a single file through bundling.
- Tools like
esbuildautomate this, turning your Deno project into a standard Worker script.
This allows you to leverage Deno's ecosystem for development while benefiting from the global reach of Cloudflare Workers.
자주 묻는 질문
“Cloudflare Workers에서 Deno 사용하기” 강의는 무료인가요?
네 — “Cloudflare Workers에서 Deno 사용하기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Edge Computing with Cloudflare Workers & Deno 강의 전체를 잠금 해제할 수 있습니다. Edge Computing with Cloudflare Workers & Deno 강의에는 총 4개의 강의가 포함되어 있습니다.
“Cloudflare Workers에서 Deno 사용하기”에서 뭘 배우나요?
Deno 모듈을 Cloudflare Workers로 배포하기 위해 트랜스파일하거나 번들링하는 방법을 알아봅니다. 브라우저에서 직접 실행하는 실습 코드로 Edge Computing with Cloudflare Workers & Deno을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Edge Computing with Cloudflare Workers & Deno을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Edge Computing with Cloudflare Workers & Deno은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.
“Cloudflare Workers에서 Deno 사용하기” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Edge Computing with Cloudflare Workers & Deno 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Edge Computing with Cloudflare Workers & Deno 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- Cloudflare Workers에서 Deno 사용하기
- Worker-Deno 프로젝트 설정
- 공유 로직 및 유틸리티
- 통합 스택 배포 및 디버깅