Denoランタイムの基本
Denoの中核機能と組み込みツール、Node.jsとの違いについて学びます。
「Denoランタイムの基本」はCoddyKit上の無料Edge Computing with Cloudflare Workers & Denoレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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 formatterdeno lint: Linter for code qualitydeno test: Test runnerdeno doc: Documentation generatordeno 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 arg2Running 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
Denoobject for runtime interactions.
These essentials make Deno a powerful and modern runtime for web development, especially at the edge!
よくある質問
「Denoランタイムの基本」レッスンは無料ですか?
はい。「Denoランタイムの基本」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Edge Computing with Cloudflare Workers & Denoコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Edge Computing with Cloudflare Workers & Denoコースには全4レッスンが含まれています。
「Denoランタイムの基本」で何を学びますか?
Denoの中核機能と組み込みツール、Node.jsとの違いについて学びます。 ブラウザで直接実行するハンズオンコードでEdge Computing with Cloudflare Workers & Denoを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Edge Computing with Cloudflare Workers & Denoを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのEdge Computing with Cloudflare Workers & Denoは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「Denoランタイムの基本」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このEdge Computing with Cloudflare Workers & Denoレッスンでコードを書いて実行できますか?
はい。すべてのEdge Computing with Cloudflare Workers & Denoレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Denoランタイムの基本
- モジュールシステムと権限
- ローカルDenoアプリの開発
- Denoアプリケーションのテスト