For faster navigation, this Iframe is preloading the Wikiwand page for Deno.

Deno

Deno
原作者瑞安·达尔
开发者Various
首次发布2018年5月13日,​6年前​(2018-05-13[1]
当前版本
  • 1.45.2 (2024年7月12日;稳定版本)[2]
编辑维基数据链接
原始码库 编辑维基数据链接
编程语言Rust, JavaScript, TypeScript, C++(V8绑定)
操作系统Linux, macOS, Microsoft Windows
类型执行环境
许可协议 编辑维基数据链接
网站deno.com 编辑维基数据

Deno是基于V8引擎和Rust语言所建立的JavaScript、TypeScriptWebAssembly执行环境,由Node.js的原始开发者瑞安·达尔所创造[3]。达尔在2018年的演讲“我为Node.js感到后悔的十件事”中宣布了Deno[4]。Deno在单个可执行档中扮演执行环境和包管理系统的角色,不需要将其分开[5][6]

历史

[编辑]

Deno于2018年瑞安·达尔的演讲“我为Node.js感到后悔的十件事”中宣布[4]。在这场演讲中,达尔提到他后悔Node.js的设计,例如没有在API中使用JavaScript的Promise、GYP建构系统、省略文件的扩展名、node_modules与package.json、使用index.js进行模块解析、V8的沙盒环境等等[7]。他在演讲的最后提出了Deno的原型,Deno旨在透过如Protocol Buffers之类的序列化工具传递消息来实现绑定系统的调用,并提供命令行接口存取控制

Deno初始版本是使用Go语言编写,并使用Protocol Buffers来实现特权(Go)与非特权(V8)之间的序列化[8]。然而因顾虑到双重运行与垃圾搜集,Go在不久后就被Rust取代[9]

为了让Deno拥有异步的事件触发环境,Tokio英语Tokio (software)也被引进来取代原本的libuv[10]

Deno原本采用Flatbuffers以进行更快的零复制序列化与反序列化[11],在2019年4月发布序列化的标准之后[12],2019年8月被移除[13]

2018年11月建立了一个以Go标准函数库为基底的标准函数库,并提供了广泛的工具,解决部分Node.js的dependency问题。[14]

Deno于2020年5月13日正式发布。[15]

Deno Deploy,受Cloudflare Workers[16]的启发,于2021年6月23日发布。[17] 于2022年5月4日宣布Beta 4改进了仪表板并增加了计费功能。Deno Deploy预计在2022年第三季度正式发布。[18]

Deno Fresh 1.0于2022年6月28日宣布。[19] 它是一个新的全栈Web框架,用于Deno,它不向客户端发送任何JavaScript。该框架没有构建步骤,这使得部署时间可以提高一个数量级。1.1版本于2022年9月8日发布。[20]

Deno SaaSKit beta于2023年4月4日宣布。[21] 它是一个开源的、现代的SaaS模板,使用Fresh和Deno构建。

概览

[编辑]

Deno目标是成为对目前的工程师来说最具有生产力的的脚本环境[5]。Deno强调事件触发架构,并提供一套非阻塞IO与阻塞IO。

Deno可用于建立网页伺服器、执行数学的运算等等。

与Node.js的比较

[编辑]

Deno与Node.js的相同之处:

  1. 皆运行于V8上。
  2. 拥有相同的事件循环
  3. 提供CLI让用户可以执行脚本语言。
  4. 庞大的实用程序

Deno与Node.js的不同之处[5]

  1. 默认模块系统是使用ES Module,而不是CommonJS
  2. 使用URL加载本地端或远程的dependencies。
  3. 使用内建的包管理器来抓取资源,因此不需要NPM
  4. 使用具有缓存机制的快照TypeScript编译器,因此Typescript也能开箱即用。
  5. 兼容具有广泛Web API的浏览器。
  6. 允许控制文件系统网络存取,以执行沙盒内的代码。
  7. 重新利用Promise、ES6、Typescript来设计API。
  8. 最小化核心API的大小,同时提供许多的标准函数库,因此不需要再使用外部的dependencies。
  9. 使用消息传递通道来调用特权系统API。

示例

[编辑]

Hello World

[编辑]

在这个JavaScript例子中,Hello [name]的资讯被打印到控制台,代码确保所提供的名字是大写的。

命令: deno run hello-world.js

/**
 * hello-world.js
 */
function capitalize(word) {
  return word.charAt(0).toUpperCase() + word.slice(1);
}

function hello(name) {
  return "Hello " + capitalize(name);
}

console.log(hello("john"));
console.log(hello("Sarah"));
console.log(hello("kai"));

/**
 * Output:
 *
 * Hello John
 * Hello Sarah
 * Hello Kai
 */

Unix cat程序

[编辑]

在这个程序中,每个命令行参数都被假定为一个文件名,文件被打开,并打印到stdout(例如控制台)。

/**
 * cat.ts
 */
import { copy } from "https://deno.land/std@0.167.0/streams/conversion.ts";
for (const filename of Deno.args) {
  const file = await Deno.open(filename);
  await copy(file, Deno.stdout);
  file.close();
}

运行该程序:

deno run --allow-read https://deno.land/std@0.167.0/examples/cat.ts /etc/passwd

HTTP网络伺服器

[编辑]

webserver.ts:

import { serve } from "https://deno.land/std@0.167.0/http/server.ts";

const port = 8080;

const handler = (request: Request): Response => {
  const body = `Your user-agent is:\n\n${
    request.headers.get("user-agent") ?? "Unknown"
  }`;

  return new Response(body, { status: 200 });
};

console.log(`HTTP webserver running. Access it at: http://localhost:8080/`);
await serve(handler, { port });

然后用以下方式运行这个:

deno run --allow-net webserver.ts

融资

[编辑]

2021年3月29日,Deno Land Inc宣布成立,由Shasta Ventures、Mozilla 公司和其他一些公司提供数百万美元的支持。它的成立是为了进一步发展 Deno 并为用户提供商业服务。[22]

一年后,Deno宣布再获得由红杉资本领投的2100万美元A轮融资。[23]

参考资料

[编辑]
  1. ^ Contributors, denoland/deno, Github. [5 July 2019]. (原始内容存档于2019-05-30). 
  2. ^ Release 1.45.2. 2024年7月12日 [2024年7月22日]. 
  3. ^ Deno: Secure V8 TypeScript Runtime from Original Node.js Creator. InfoQ. [2019-05-17]. (原始内容存档于2020-01-08). 
  4. ^ 4.0 4.1 JSConf, 10 Things I Regret About Node.js - Ryan Dahl - JSConf EU 2018, 2018-06-06 [2019-05-17], (原始内容存档于2019-05-17) 
  5. ^ 5.0 5.1 5.2 Deno Manual. deno.land. [2019-05-17]. (原始内容存档于2020-01-08). 
  6. ^ Paul Krill. Ryan Dahl’s Node.js regrets lead to Deno. InfoWorld. 2018-06-21 [2020-06-03]. (原始内容存档于2019-06-10). 
  7. ^ Dahl, Ryan. Design mistakes in Node (PDF). Github. 2018-06-06 [2020-06-03]. (原始内容存档 (PDF)于2020-02-22). 
  8. ^ denoland/deno, branch "golang". Github. 
  9. ^ Suggestion: Look into porting to Rust and using Tokio. GitHub. [2020-06-03]. (原始内容存档于2018-08-29). 
  10. ^ Tokio - The asynchronous run-time for the Rust programming language.. Tokio.rs. [2020-06-03]. (原始内容存档于2020-05-20). 
  11. ^ Protobuf seems like a lot of overhead for this use case?. Github. [2020-06-03]. (原始内容存档于2020-12-08). 
  12. ^ Replace flatbuffers. GitHub. [2020-06-03]. (原始内容存档于2020-11-26). 
  13. ^ Remove flatbuffers. GitHub. [2020-06-03]. (原始内容存档于2020-11-26). 
  14. ^ denoland/deno_std: deno standard modules. Github. [2020-06-03]. (原始内容存档于2020-06-15). 
  15. ^ Deno 1.0. deno.land. [2020-05-14]. (原始内容存档于2020-05-14). 
  16. ^ Dahl, Ryan. JavaScript Containers. tinyclouds.org. 4 May 2022. (原始内容存档于4 May 2022). 
  17. ^ Krill, Paul. Deno Company unveils server-side JavaScript hosting service. InfoWorld. 2021-06-24 [2022-04-14]. (原始内容存档于27 Jun 2022) (英语). 
  18. ^ Krill, Paul. Deno Deploy moves toward GA, adds paid plan. InfoWorld. 2022-06-03 [2022-07-24]. (原始内容存档于2023-06-07) (英语). 
  19. ^ Luca, Casonato. Introduction Fresh 1.0 as new full stack web framework for Deno. Deno Blog. 2022-07-22 [2022-07-24] (英语). 
  20. ^ Casonato, Luca. Fresh 1.1 - automatic JSX, plugins, DevTools, and more. Deno Blog. 2022-09-08 [2022-09-10] (英语). 
  21. ^ Jiang, Andy. Announcing Deno SaaSKit: an open-source SaaS template built with Fresh. Deno Blog. 2023-04-04 [2022-04-04] (英语). 
  22. ^ Ryan Dahl, Bert Belder. Announcing the Deno Company. 2021-03-29. 
  23. ^ Deno raises $21M. deno.com. (原始内容存档于22 June 2022). 

外部链接

[编辑]

官方网站 在维基数据上编辑此内容页面存档备份,存于互联网档案馆


{{bottomLinkPreText}} {{bottomLinkText}}
Deno
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?