May 2020 saw the release of Deno 1.0, and it’s been a pretty popular topic of conversation. If you’re wondering what the fuss is all about, you’ve come to the right place!
In this article, I hope to give you an overview of what Deno is. We’ll take a look at its key features, and ask why you might want to start learning this new tool.
What is Deno?
If you’re aware of Node.js, and you’re thinking that Deno sounds pretty similar, you’d be right. Deno is the brainchild of Node’s creator, Ryan Dahl, who created Deno to address what he sees as the design flaws in Node. The aims of the project are to provide a scripting environment that is secure by default, that treats TypeScript as a first-class language, and that is as browser-compatible as possible (where practical).
Deno is designed to be secure out of the box. All code is executed in a secure sandbox by default, which means you need to give explicit permission to allow a program to access the network or the filesystem.
Programs can be granted permissions with the following command-line flags:
- -A, –allow-all: allow all permissions (disables all security).
- –allow-env: allow getting and setting of environment variables.
- –allow-hrtime: allow high resolution time measurement (can be used in timing attacks and fingerprinting).
- –allow-net=: allow network access. Optionally takes a comma-separated whitelist of domains.
- –allow-plugin: allow loading plugins (unstable feature).
- –allow-read=: allow file system read access. Optionally takes a comma-separated whitelist of directories or files.
- –allow-run: allow running subprocesses.
- –allow-write=: allow file system write access. Optionally takes a comma-separated whitelist of directories or files.
First-class TypeScript Support
Using External Code
As Ryan mentioned in his talk, one of his goals for Deno was to avoid the need for a package manager. Unlike with runtimes/languages such as Node.js and PHP (which use the npm and composer package managers respectively), there’s no package manager for Deno.
Instead, external packages are imported directly via a URL:
import Client from "https://firstname.lastname@example.org/mod.ts";
The first time you run your script, Deno will fetch, compile, and cache all the imports so that subsequent starts are lightning fast. Obviously there are times when you may want to force Deno to re-fetch the imports, and you can do this with the
deno cache --reload my_module.ts