Deno: 1.0 officially scheduled on May, 13! Review of the features
π€ Introduction
It all started 2 years ago, Ryan Dahl, the creator of Node.js gave a talk at the JSConf 2018 β10 Things I Regret About Node.jsβ:
It was actually 7 things πhe regrets about Node.js:
Not sticking with Promises: he added them in June 2009 but removed them in February 2010, with Promises in Node.js, It could have sped up the delivery of a standard on async/await
Security: Node process has wide access including system calls, network, disk I/O
The build system: You need GYP for compiling native C library and link it to Node.js modules, Chrome used to use GYB but now Node is the sole user
package.json: it includes unnecessary information such as LICENCES and repository - also it uses a centralized repository for modules
node_modules: maybe the worse for him, resolution is complex, folder size is frequently hugeβ¦
require without extension: the module load has to guess the extension and this is not how browser works
index.js: it complicates the module loading system
π Deno was born
With all the things learned by building Node.js, Ryan came up with a new idea named Deno:
A secure runtime for JavaScript and TypeScript.
Deno aims to provide a productive and secure scripting environment for the modern programmer. It is built on top of V8, Rust, and TypeScript.
Instead of using C++ as in Node.js, Itβs built on top of Rust and It uses Tokio under the hood.
It brings many of the best open-source technologies together.
π Deno 1.0 - Release scheduled on May 13
So after almost 2 years, the API has been officially frozen and the launch of the 1.0 is scheduled on May 13. It addresses the design flaws that Ryan talked about in his lecturez.
Getting started π
To install Deno, here are the instructions:
Using Shell:
1 | curl -fsSL https://deno.land/x/install/install.sh | sh |
Or using PowerShell:
1 | iwr https://deno.land/x/install/install.ps1 -useb | iex |
Using Homebrew (macOS or Linux):
1 | brew install deno |
Using Chocolatey (Windows):
1 | choco install deno |
See deno_install for more installation options.
Whatβs in the 1.0 release ? π
Deno 1.0 comes fully loaded with many useful features for modern development. In the following section we are going to cover all the greatest features coming in the new release.
Supports TypeScript out of the box
Well, everything is in the title. You can also bring your own tsconfig.json
by using the following command:
1 | deno run -c tsconfig.json [program.ts] |
Security by design
Programs run with no permissions by default and if the code needs permissions will be alerted.
You need to use command-line options to tell Deno what permissions the program needs. By running deno run -h
you will see the full list of permissions:
1 | -A, --allow-all Allow all permissions |
ECMAScript modules built-in
Deno does not support require()
, It uses ES Modules:
1 | import * as log from "https://deno.land/std/log/mod.ts"; |
The package management is super simple, just provide the URL of what you want to use. As the URL may change, for security purposes, by using a lock file (using the βlock command line flag) you can ensure youβre running the code you expect to be.
Super simple package management
Deno does not use npm. It uses modules referenced as URLs or file paths:
1 | import { serve } from "https://deno.land/std@v0.42.0/http/server.ts"; |
You can specify version of the package in directly in the URL. For example https://deno.land/std@v0.42.0/http/server.ts
.
Also, Deno offers a built-in dependency inspector (deno info
).
Use deps.ts
instead of package.json
The Deno convention for dependency management is using a unique file called deps.ts
for storing all the dependency. For example, we can look at the deps.ts
of oak, the popular middleware framework for Denoβs http server inspired by Koa:
1 | // Copyright 2018-2020 the oak authors. All rights reserved. MIT license. |
(Source: https://github.com/oakserver/oak/blob/master/deps.ts)
JSDoc built-in with deno doc
We strive for complete documentation. Deno has JSDoc built-in so you can use write JSDoc comments in files.
Test runner with Deno.test()
std/testing/asserts.ts
module provides range of assertion helpers:
equal()
assert()
assertEquals()
assertNotEquals()
assertStrictEq()
assertStrContains()
assertMatch()
assertArrayContains()
assertThrows()
assertThrowsAsync()
unimplemented()
unreachable()
For example:
1 | import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; |
(Source: https://github.com/denoland/deno/tree/master/std/testing)
Run deno test file.spec.ts
:
1 | Compile file.spec.ts |
Formatting with deno fmt <files>
It is provided by dprint, an alternative to the famour Prettier.
Compiling and bundling with deno bundle
It is currently marked as unstable. So use it at your own risk.
Debugger deno run -A --inspect-brk fileToDebug.ts
With this you can open the Chrome debugger (chrome://inspect
) and start inspect the process!
Reviewed (audited) Standard library
The standard library is garanteed to work with Deno, they do not have external dependencies and they are reviewed by the Deno core team. Modules are tagged in accordance with Deno releases, so version v0.4.0 of a standard library is garanteed to work with Deno v0.4.0.
List of modules:
Usage of W3C web standards
Deno provides the following W3C web standards APIs:
Request
Response
addEventListener
atob
btoa
ReadableStream
clearInterval
clearTimeout
dispatchEvent
fetch
queueMicrotask
removeEventListener
setInterval
setTimeout
AbortSignal
Blob
File
FormData
Headers
URL
URLSearchParams
console
isConsoleInstance
location
onload
onunload
self
window
AbortController
CustomEvent
DOMException
ErrorEvent
Event
EventTarget
MessageEvent
TextDecoder
TextEncoder
Worker
ImportMeta
Location
Example: Build a simple HTTP Server using Deno π
1 | import { Application } from "https://deno.land/x/oak/mod.ts"; |
Letβs run it using deno server.ts
:
1 | Compile file:///.../server.ts |
Letβs add the missing permission deno --allow-net server.ts
:
1 | $ curl http://127.0.0.1:8000 |
You are now ready for the upcoming release of Deno 1.0 - Stay tuned π Please leave me comment if youβve liked this article! You can also follow me on Twitter @loverdeolivier π