入门
Deno
(/ˈdiːnoʊ/,发音为
dee-no
)是一个
开源 的 JavaScript、
TypeScript 和 WebAssembly 运行时,具有安全的默认设置和出色的开发体验。它基于 V8,
Rust 和 Tokio 构建。
让我们在不到五分钟的时间里创建并运行你的第一个 Deno 程序。
安装 Deno Jump to heading
使用下面的终端命令之一在你的系统上安装 Deno 运行时。
curl -fsSL https://deno.land/install.sh | sh
irm https://deno.land/install.ps1 | iex
curl -fsSL https://deno.land/install.sh | sh
更多安装选项可以在这里找到。安装后,你应该在系统路径中有 deno
可执行文件。你可以通过运行以下命令来验证安装是否成功:
deno --version
你好,世界 Jump to heading
Deno 可以运行 JavaScript 和 TypeScript,无需额外的工具或配置。让我们创建一个简单的“你好,世界”程序,并用 Deno 运行它。
创建一个名为 main
的 TypeScript 或 JavaScript 文件,并包含以下代码:
main.ts
function greet(name: string): string {
return `Hello, ${name}!`;
}
console.log(greet("world"));
main.js
function greet(name) {
return `Hello, ${name}!`;
}
console.log(greet("world"));
保存文件并使用 Deno 运行它:
$ deno main.ts
Hello, world!
$ deno main.js
Hello, world!
后续步骤 Jump to heading
恭喜!你刚刚运行了你的第一个 Deno 程序。继续阅读以了解更多关于 Deno 运行时的信息。