0Pricing
Edge Computing with Cloudflare Workers & Deno · บทเรียน

พื้นฐานสำคัญของ Deno Runtime

สำรวจฟีเจอร์หลัก เครื่องมือในตัวของ Deno และความแตกต่างจาก Node.js

พื้นฐานสำคัญของ Deno Runtime เป็นบทเรียน Edge Computing with Cloudflare Workers & Deno ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Edge Computing with Cloudflare Workers & Deno และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Edge Computing with Cloudflare Workers & Deno มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Welcome to Deno Essentials

Welcome! In this lesson, we'll dive into Deno, a modern, secure runtime for JavaScript and TypeScript.

Created by Ryan Dahl (who also created Node.js), Deno addresses some of the design choices made in Node.js, focusing on security and a great developer experience.

Security First: Deno's Approach

One of Deno's biggest differences is its security model. By default, Deno scripts run in a sandbox, meaning they have no access to:

  • The file system
  • The network
  • Environment variables
  • Subprocesses

You must explicitly grant these permissions using command-line flags. This prevents malicious code from doing harm without your knowledge.

Built-in Tooling

Deno comes with a powerful set of built-in tools. Forget installing separate packages for formatting, linting, or testing!

Key tools include:

  • deno fmt: Code formatter
  • deno lint: Linter for code quality
  • deno test: Test runner
  • deno doc: Documentation generator
  • deno compile: Compiles scripts into self-contained executables

This integrated experience simplifies project setup and maintenance.

Native TypeScript Support

Deno supports TypeScript out of the box. This means you can write TypeScript code without needing a separate compilation step or tsconfig.json file.

It also embraces ES Modules, allowing you to import modules directly from URLs, much like how browsers work. No more node_modules folder!

Your First Deno Program

Let's write a simple Deno program. Save this as hello.ts (or .js) and run it with deno run hello.ts.

console.log("Hello from Deno!");
console.log("Deno is awesome.");

Deno vs. Node.js: Core Differences

While both Deno and Node.js are JavaScript runtimes, they have fundamental differences:

  • Security: Deno is secure by default (permissions needed), Node.js has full access.
  • TypeScript: Deno supports TS natively, Node.js requires transpilation.
  • Tooling: Deno has built-in tools (fmt, lint, test), Node.js relies on npm packages.
  • Module System: Deno uses URL-based ES Modules, Node.js uses CommonJS (though ES Modules are gaining traction).
  • Standard Library: Deno has a robust standard library, Node.js has a smaller core.

The Global Deno Object

Deno exposes a global Deno object that provides access to runtime-specific APIs, like file system operations, network access, and environment variables.

Here's how you can access command-line arguments passed to your script:

console.log("Arguments:", Deno.args);

// Try running: deno run my_script.ts arg1 arg2

Running with Permissions

To demonstrate Deno's permission model, let's try to read a file. This script will fail without explicit permission.

To run it successfully, you'll need to add the --allow-read flag: deno run --allow-read file_reader.ts

try {
  const content = Deno.readTextFileSync("data.txt");
  console.log("File content:\n" + content);
} catch (error) {
  console.error("Error reading file: ", error.message);
  console.error("Hint: Try 'deno run --allow-read file_reader.ts'");
}

Deno Essentials Check

Which of the following statements about Deno is TRUE?

Recap: Deno's Foundation

Great job! In this lesson, you've learned about Deno's foundational features:

  • Its security-first approach with a granular permission model.
  • The convenience of its built-in tooling.
  • Native TypeScript and ES Module support.
  • The global Deno object for runtime interactions.

These essentials make Deno a powerful and modern runtime for web development, especially at the edge!

คำถามที่พบบ่อย

บทเรียน “พื้นฐานสำคัญของ Deno Runtime” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “พื้นฐานสำคัญของ Deno Runtime” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Edge Computing with Cloudflare Workers & Deno ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Edge Computing with Cloudflare Workers & Deno มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “พื้นฐานสำคัญของ Deno Runtime”

สำรวจฟีเจอร์หลัก เครื่องมือในตัวของ Deno และความแตกต่างจาก Node.js คุณปฏิบัติ Edge Computing with Cloudflare Workers & Deno ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Edge Computing with Cloudflare Workers & Deno หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Edge Computing with Cloudflare Workers & Deno บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “พื้นฐานสำคัญของ Deno Runtime” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Edge Computing with Cloudflare Workers & Deno นี้ได้ไหม

ได้ บทเรียน Edge Computing with Cloudflare Workers & Deno ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. พื้นฐานสำคัญของ Deno Runtime
  2. ระบบโมดูลและสิทธิ์การอนุญาต
  3. การพัฒนาแอป Deno ในเครื่อง
  4. การทดสอบแอปพลิเคชัน Deno
← กลับไปที่ Edge Computing with Cloudflare Workers & Deno