Deno Core Features: Part 1

Discover some of the core features behind Deno and learn its main differences from Node.js.

Deno offers rich features to guarantee an improved and smooth development experience.
The core members expressed their goal with the following sentence:

Deno aims to be a productive and secure scripting environment for the modern programmer.

Let’s analyze Deno’s main features that make it so attractive.

Security

Security has a central role in Deno, and that’s the reason why its programs are defined as secure by default. What does this mean exactly?

Sandbox security layer

Any Deno module is executed in a sandbox security layer by default, preventing access to the disk, the environment, the network, or the possibility to run any external script unless explicitly allowed through permissions. We grant permissions to a program by using dedicated flags when running the code itself from the command line.
This aspect is a significant improvement compared to Node applications. When a Node script is executed, it has the same access rights as the user.

Example

Let’s see a simple example together to understand better how permissions work.

The command below executes a remote script file (cat.ts) granting it read access to a target file test.txt:

deno run --allow-read https://deno.land/std@0.123.0/examples/cat.ts test.txt

The cat.ts script is part of the Deno standard library and we can invoke it directly from the terminal. It accepts one or more file names passed as argument and it prints their content:

Get hands-on with 1400+ tech skills courses.