Deno (software)

{{Short description|Secure JavaScript and TypeScript runtime}}

{{Infobox software

| name = Deno

| logo = Deno Logo 2024.svg

| logo caption = Logo used since 2024

| author = Ryan Dahl

| developer = Deno Land Inc{{cite web|url=https://deno.com/blog/the-deno-company|title=Announcing the Deno Company|author=Ryan Dahl, Bert Belder|date=2021-03-29}} and contributors

| released = {{Start date and age|2018|05|13}}{{cite web | url=https://github.com/denoland/deno/graphs/contributors | access-date=5 July 2019|title=Contributors, denoland/deno, Github| website=GitHub}}

| discontinued =

| latest release version = {{wikidata|property|reference|edit| Q65070939 |P348}}

| latest release date = {{start date and age|{{wikidata|qualifier| Q65070939 |P348|P577}}}}

| repo = {{URL|https://github.com/denoland/deno}}

| programming language = TypeScript, JavaScript, Rust, C++ (V8 bindings)

| operating system = Linux, macOS, Microsoft Windows

| genre = Runtime environment

| license = MIT License{{cite web|title=deno/LICENSE at main|url=https://github.com/denoland/deno/blob/main/LICENSE|website=GitHub|access-date=5 July 2019}}

}}

Deno ({{IPAc-en|d|iː|n|oʊ}}{{cite web|url=https://docs.deno.com/runtime/manual|title=Deno Manual|website=deno.com|access-date=2019-05-17}}) is a runtime for JavaScript, TypeScript, and WebAssembly that is based on the V8 JavaScript engine and the Rust programming language. Deno was co-created by Ryan Dahl, the creator of Node.js{{cite web |last=Schiemann |first=Dylan |date=December 26, 2018 |title=Deno: Secure V8 TypeScript Runtime from Original Node.js Creator |url=https://www.infoq.com/news/2018/12/deno-v8-typescript |url-status=live |access-date=May 17, 2019 |website=InfoQ |language=en-US |archive-date=May 17, 2019 |archive-url=https://web.archive.org/web/20190517060537/https://www.infoq.com/news/2018/12/deno-v8-typescript }} and Bert Belder.{{Cite news |title=The JavaScript ecosystem is 'hopelessly fragmented'... so here is another runtime: Deno is now a company |url=https://www.theregister.com/2021/04/06/deno_is_now_a_company/ |archive-url=http://web.archive.org/web/20240625220804/https://www.theregister.com/2021/04/06/deno_is_now_a_company/ |archive-date=2024-06-25 |access-date=2025-01-10 |language=en}}

Deno explicitly takes on the role of both runtime and package manager within a single executable, rather than requiring a separate package-management program.{{cite web|url=https://www.infoworld.com/article/3283250/ryan-dahls-nodejs-regrets-lead-to-deno.html|archive-url=https://web.archive.org/web/20190414195245/https://www.infoworld.com/article/3283250/ryan-dahls-nodejs-regrets-lead-to-deno.html|archive-date=2019-04-14|title=Ryan Dahl's Node.js regrets lead to Deno|author=Paul Krill|publisher=InfoWorld|date=2018-06-21}}

History

Deno was announced at JSConf EU 2018 by Ryan Dahl in his talk "10 Things I Regret About Node.js".{{cite AV media |last=Dahl | first=Ryan |title=10 things I regret about Node.js | publisher=JSConf EU | date=2018-06-06 | via=YouTube | url=https://www.youtube.com/watch?v=M3BM9TB-8yA | access-date=2019-05-17}} In his talk, Dahl mentioned his regrets about the initial design decisions with Node.js, focusing on his choices of not using promises in API design, usage of the legacy build system GYP, node_modules and package.json, leaving out file extensions, magical module resolution with index.js and breaking the sandboxed environment of V8.{{cite web|url=https://github.com/denolib/awesome-deno/blob/main/resources/design-mistakes-in-node/design-mistakes-in-node.pdf|title=Design mistakes in Node|last=Dahl|first=Ryan|date=2018-06-06|website=Github}} He eventually presented the prototype of Deno, aiming to achieve system call bindings through message passing with serialization tools such as Protocol Buffers, and to provide command line flags for access control.

Deno was initially written in Go and used Protocol Buffers for serialization between privileged (Go, with system call access) and unprivileged (V8) sides.{{cite web|url=https://github.com/denoland/deno/tree/golang|title=denoland/deno, branch "golang"|website=GitHub}} However, Go was soon replaced with Rust due to concerns of double runtime and garbage collection pressure.{{cite web|url=https://github.com/denoland/deno/issues/205|title=Suggestion: Look into porting to Rust and using Tokio|website=GitHub}} Tokio was introduced in place of libuv as the asynchronous event-driven platform,{{cite web|url=https://tokio.rs/|title=Tokio - The asynchronous run-time for the Rust programming language.|website=Tokio.rs}} and FlatBuffers was adopted for faster, "zero-copy" serialization and deserialization{{cite web|url=https://github.com/denoland/deno/issues/269|title=Protobuf seems like a lot of overhead for this use case?|website=GitHub}} but later in August 2019, FlatBuffers was removed{{cite web|url=https://github.com/denoland/deno/pull/2818|title=Remove flatbuffers|website=GitHub}} after publishing benchmarks that measured a significant overhead of serialization in April 2019.{{cite web |date=April 15, 2019 |title=Replace flatbuffers |url=https://github.com/denoland/deno/issues/2121 |access-date=July 11, 2019 |website=GitHub |language=en-US}}

A standard library, modeled after Go's standard library, was created in November 2018 to provide extensive tools and utilities, partially solving Node.js' dependency tree explosion problem.{{cite web|url=https://github.com/denoland/deno_std|title=denoland/deno_std: deno standard modules|website=GitHub|date=3 March 2022}}

The official Deno 1.0 was released on May 13, 2020.{{cite web|title=Deno 1.0|url=https://deno.com/blog/v1|website=deno.com|date=13 May 2020 |access-date=2020-05-14}}

Deno Deploy, inspired by Cloudflare Workers,{{cite web |title=JavaScript Containers |url=https://tinyclouds.org/javascript_containers |archive-url=https://archive.today/20220504191522/https://tinyclouds.org/javascript_containers |date=4 May 2022 |archive-date=4 May 2022 |website=tinyclouds.org |last=Dahl |first=Ryan}} was released on June 23, 2021.{{cite web |last=Krill |first=Paul |date=2021-06-24 |title=Deno Company unveils server-side JavaScript hosting service |url=https://www.infoworld.com/article/3622914/deno-company-unveils-server-side-javascript-hosting-service.html |access-date=2022-04-14 |website=InfoWorld |language=en |archive-url=https://archive.today/20220627113153/https://www.infoworld.com/article/3622914/deno-company-unveils-server-side-javascript-hosting-service.html |archive-date=27 Jun 2022}} Announced May 4, 2022 Beta 4 improved the dashboard and added billing functionality.{{cite web |last=Krill |first=Paul |date=2022-06-03 |title=Deno Deploy moves toward GA, adds paid plan |url=https://www.infoworld.com/article/3663129/deno-deploy-moves-toward-ga-adds-paid-plan.html |access-date=2022-07-24 |website=InfoWorld |language=en}}

Deno Fresh 1.0 was announced June 28, 2022.{{cite web |last=Luca |first=Casonato |date=2022-07-22 |title=Introduction Fresh 1.0 as new full stack web framework for Deno |url=https://deno.com/blog/fresh-is-stable |access-date=2022-07-24 |website=Deno Blog |language=en}} It features a new full stack web framework for Deno that by default sends zero JavaScript to the client. The framework has no build step which allows for an order of magnitude improvements in deployment times. Version 1.1 was released September 8, 2022.{{cite web |last=Casonato |first=Luca|date=2022-09-08 |title=Fresh 1.1 - automatic JSX, plugins, DevTools, and more |url=https://deno.com/blog/fresh-1.1 |access-date=2022-09-10 |website=Deno Blog |language=en}}

Deno SaaSKit beta was announced April 4, 2023.{{cite web |last=Jiang |first=Andy|date=2023-04-04 |title=Announcing Deno SaaSKit: an open-source SaaS template built with Fresh |url=https://deno.com/blog/announcing-deno-saaskit |access-date=2022-04-04 |website=Deno Blog |language=en}} It is an open-source, modern SaaS template built with Fresh and Deno.

Deno 2 was released October 9, 2024.{{Cite web |date=2024-10-09 |title=Announcing Deno 2 |url=https://deno.com/blog/v2.0 |access-date=2024-10-27 |website=Deno Blog |language=en}} It primarily brings Node.js compatibility improvements and removes deprecated features.

Overview

Deno aims to be a productive and secure scripting environment for the modern programmer. Similar to Node.js, Deno emphasizes event-driven architecture, providing a set of non-blocking core I/O utilities, along with their blocking versions. Deno could be used to create web servers, perform scientific computations, etc. Deno is open source software under the MIT License.{{cite web|title=Deno Is Ready for Production|url=https://www.infoq.com/news/2020/06/deno-1-ready-production/|access-date=2020-07-01|website=InfoQ|language=en}}

= Comparison with Node.js =

Deno and Node.js are both runtimes built on the V8 JavaScript engine developed by the Chromium Project, the engine used for Chromium and Google Chrome web browsers. They both have internal event loops and provide command-line interfaces for running scripts and a wide range of system utilities.

Deno mainly deviates from Node.js in the following aspects:

  1. Supports only ES Modules like browsers where Node.js supports both ES Modules and CommonJS. CommonJS support in Deno is possible by using a compatibility layer.{{cite web|url=https://nodejs.org/api/esm.html|title = Modules: ECMAScript modules | Node.js v17.6.0 Documentation}}{{cite web|url=https://docs.deno.com/runtime/manual|title=Deno - A modern runtime for JavaScript and TypeScript}}
  2. Supports URLs for loading local or remote dependencies, similar to browsers, and uses module specifiers like npm: and node: to import NPM or polyfill Node.JS modules. Node.js supports both URLs{{cite web|url=https://nodejs.org/api/esm.html#https-and-http-imports|title=Modules: ECMAScript modules | Node.js v17.6.0 Documentation}} and modules.
  3. Does not require a package manager for resource fetching, thus no need for a registry like npm.{{cite web|url=https://docs.deno.com/runtime/tutorials/manage_dependencies|title = Deno - A modern runtime for JavaScript and TypeScript}}
  4. Supports TypeScript out of the box,{{cite web |title=Deno.js in Production. Key Takeaways. |url=https://medium.com/@sdesalas/deno-js-in-production-main-takeaways-247a2fd2d198 |website=Medium.com |access-date=16 May 2022}} using a snapshotted TypeScript compiler or the swc compiler{{cite web|url=https://github.com/swc-project/swc|title = Documentation|website = GitHub|date = 3 March 2022}} with caching mechanisms.
  5. Aims for better compatibility with browsers with a wide range of Web APIs.
  6. Restricts file system and network access by default in order to run sandboxed code.
  7. Supports a single API to utilize promises, ES6 and TypeScript features whereas Node.js supports both promise and callback APIs.
  8. Minimizes core API size, while providing a large standard library with no external dependencies.
  9. Uses message passing channels for invoking privileged system APIs and using bindings.

Funding

On March 29, 2021, Deno Land Inc was announced, with backing in millions of dollars from Shasta Ventures, Mozilla Corporation and a few others. It was established to further the development of Deno and provide a commercial offering to users.

A year on, Deno announced a further $21 million in Series A funding led by Sequoia Capital.{{cite web |date= 21 June 2022|title=Deno raises $21M |url=https://deno.com/blog/series-a |archive-url=https://archive.today/20220622122104/https://deno.com/blog/series-a |archive-date=22 June 2022 |website=deno.com}}

Examples

{{cleanup|date=July 2023|reason=Reads like a software tutorial. Some code examples may be useful to illustrate aspects of the framework, but they should be selected for the purpose of providing context to an encyclopedia article on the software.}}

Global Deno namespaces expose APIs that are not available in the browser.

An implementation of the Unix cat program: [https://docs.deno.com/runtime/tutorials/unix_cat]

/**

* cat.ts

*/

for (const filename of Deno.args) {

const file = await Deno.open(filename);

await file.readable.pipeTo(Deno.stdout.writable, { preventClose: true });

}

A simple Web server: [https://deno.com/blog/v1.35]

Deno.serve((req) => new Response("hello world"));

Deno automatically downloads and caches the remote standard library files when the script is run, and then compiles the code.

Similarly, it can run a standard library script (such as a file server) directly without explicitly downloading, by providing the URL as the input filename (-A turns on all permissions):

$ deno run -A https://deno.land/std/http/file_server.ts

Download https://deno.land/std/http/file_server.ts

Compile https://deno.land/std/http/file_server.ts

...

HTTP server listening on http://0.0.0.0:4500/

References

{{reflist|colwidth=30em}}