Worker-Deno 프로젝트 설정
로컬 개발에는 Deno를, 배포에는 Cloudflare Workers를 결합하는 프로젝트를 구성합니다.
Worker-Deno 프로젝트 설정은(는) CoddyKit의 무료 Edge Computing with Cloudflare Workers & Deno 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Edge Computing with Cloudflare Workers & Deno 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Edge Computing with Cloudflare Workers & Deno 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Deno & Workers: Best of Both
Welcome! In this lesson, we'll learn how to set up a project that uses Deno for local development and Cloudflare Workers for deployment to the edge.
This powerful combination lets you leverage the best features of both platforms.
Why Combine Deno & Workers?
Deno offers a fantastic local developer experience with its built-in tools for formatting, linting, and testing. Cloudflare Workers, on the other hand, provide a serverless platform to deploy your code globally, close to your users.
A combined setup allows you to:
- Develop and test locally with Deno's robust tooling.
- Deploy your application to Cloudflare's low-latency edge network.
- Reuse core application logic across both environments.
Organizing Your Hybrid Project
A typical project structure for Deno and Workers involves separating entry points while sharing core logic. Here's a common layout:
src/: Contains your shared Deno-compatible logic.worker-entry.ts: The main entry point for your Cloudflare Worker.deno-local.ts: A script to run your application locally using Deno.wrangler.toml: Cloudflare Worker configuration file.
This keeps things tidy and manageable.
Cloudflare Worker Setup
We'll assume you have the Wrangler CLI installed and configured from previous lessons. This tool is essential for developing and deploying Cloudflare Workers.
Your wrangler.toml file will define how your Worker builds and deploys. For Deno projects, it often points to a bundled JavaScript output file.
Basic Deno Project Init
For local Deno development, you simply create your .ts or .js files. Deno doesn't require a package.json or a node_modules folder like Node.js.
You can also use a deno.json file to configure project-specific settings, like tasks, formatting rules, and imports.
Writing Reusable Code
The key to a successful hybrid project is writing core application logic that can run in both Deno and Worker environments.
- Use standard Web APIs (e.g.,
Request,Response,URL). - Avoid Node.js-specific APIs.
- Place this shared logic in a common directory, like
src/.
This ensures your code works seamlessly in both contexts.
Deno Local Server Example
Here's how you might set up a basic Deno server to run your shared logic locally. This allows for quick testing and iteration without deploying to the edge.
import { serve } from "https://deno.land/std/http/server.ts";
// This function would typically be imported from a shared 'src/' file.
function handleLocalRequest(request: Request): Response {
const url = new URL(request.url);
if (url.pathname === "/local-greet") {
return new Response("Hello from Deno local server!", { status: 200 });
}
return new Response("Not Found", { status: 404 });
}
console.log("Deno server running on http://localhost:8000/");
serve(handleLocalRequest, { port: 8000 });
Cloudflare Worker Entry Point
Your Cloudflare Worker's entry point (e.g., worker-entry.ts) will import and use the same shared logic. Wrangler will then bundle this Deno-compatible code into a single JavaScript file for deployment.
export default {
async fetch(request: Request): Promise<Response> {
const url = new URL(request.url);
// Imagine importing and using a shared function here
// import { handleRequest } from './src/handler.ts';
// return handleRequest(request);
// For this example, we'll use a simplified inline logic
if (url.pathname === "/edge-greet") {
return new Response("Hello from Cloudflare Worker!", { status: 200 });
}
return new Response("Not Found", { status: 404 });
},
};
Bundling Deno for Workers
Cloudflare Workers execute standard JavaScript. Since Deno often uses TypeScript and a URL-based module system, your Deno code needs to be transpiled (converted to JavaScript) and bundled into a single file.
Wrangler handles this process automatically if configured correctly, often using tools like esbuild internally. This ensures your Deno logic runs efficiently at the edge.
Project Setup Check
When setting up a project to use Deno for local development and Cloudflare Workers for deployment, what is a primary benefit of this hybrid approach?
Project Setup Recap
In this lesson, we explored how to structure a project that utilizes Deno for local development and Cloudflare Workers for edge deployment. We discussed the benefits of this approach, how to organize shared code, and saw examples of Deno local server and Worker entry points.
Next, we'll dive into implementing shared utility functions and business logic that can be reused across both environments.
자주 묻는 질문
“Worker-Deno 프로젝트 설정” 강의는 무료인가요?
네 — “Worker-Deno 프로젝트 설정” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Edge Computing with Cloudflare Workers & Deno 강의 전체를 잠금 해제할 수 있습니다. Edge Computing with Cloudflare Workers & Deno 강의에는 총 4개의 강의가 포함되어 있습니다.
“Worker-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개 중 2번째 강의입니다.
“Worker-Deno 프로젝트 설정” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Edge Computing with Cloudflare Workers & Deno 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Edge Computing with Cloudflare Workers & Deno 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- Cloudflare Workers에서 Deno 사용하기
- Worker-Deno 프로젝트 설정
- 공유 로직 및 유틸리티
- 통합 스택 배포 및 디버깅