Deno: The Official Node.js-Successor?
Tags: deno, node, javascript, webdev
Published: 2020-05-19 08:52:01

---
title: Deno: The Official Node.js-Successor?
published: true
date: 2020-05-18 12:38:00 UTC
tags: deno, node, javascript, webdev
cover_image: https://files.sebnilsson.com/web/images/deno/deno-cover-image.jpg
canonical_url: https://sebnilsson.com/blog/deno-the-official-nodejs-successor/
---

Why is [the announcement of Deno 1.0](https://deno.land/v1) possibly **very exciting**? Are there **enough upsides to warrant a switch** from Node.js to [Deno](https://github.com/denoland/deno)?

The announcement of 1.0 was done middle of May 2020, but the initial announcement came in a presentation named [_10 Things I Regret About Node.js_ by Ryan Dahl](https://youtu.be/M3BM9TB-8yA) in mid-2018.

Deno is not just a rearrangement of the first two and the last two letters of "Node". It's built on top of more than **11 years of experience from Node.js** running in production all over the world, **by the original creator of Node.js**. So this does not seem like another case of _"I don't like how this project is handled, [so I'm making my own fork](https://www.infoworld.com/article/2855057/why-iojs-decided-to-fork-nodejs.html)"_, it's a completely new implementation.

## 10 Regrets about Node.js

The 10 things Ryan Dahl regretted about Node.js, which he acknowledges are **impossible to change now** , seem to be **large motivators for the creation of Deno**. It's worth noting that JavaScript has changed a lot during its 11 years of existence and Node has driven a lot of those changes.

The numbered [regrets brought up in the talk](https://youtu.be/M3BM9TB-8yA) were:

1. **Not sticking with promises** : Promises allow the usage of `async`/`await` and avoids "[Callback Hell](http://callbackhell.com/)".
2. **Security** : Your linter shouldn't get complete access to your computer and network.
3. **The Build System (GYP)**: Awful experience for users. It's a non-JSON, Python adaptation of JSON.
4. **`package.json`** : Not a strictly necessary abstraction and doesn't exist on the web. Includes all sorts of unnecessary information.
5. **`node_modules`** : Massively complicates the module resolution. Deviates greatly from browser semantics.
6. **`require("module")` without the extension "`.js`"**: Needlessly less explicit. Module loader has to query the file system at multiple locations.
7. **`index.js`** : Needlessly complicated the module loading system.

It was also mentioned that Deno supports the following things:

- Unhandled promises should die immediately
- Support top-level `await`
- Browser compatible where functionality overlaps

## Introducing Deno

[Deno](https://deno.land/) is a runtime for both JavaScript and [TypeScript](https://www.typescriptlang.org/), built on the [V8 JavaScript engine](https://v8.dev/) and [Rust](https://www.rust-lang.org/), with the asynchronous runtime [Tokio](https://tokio.rs/).

The [feature highlights](https://deno.land/manual#feature-highlights), as of version 1.0, are:

- **Secure by default** : Access to files, network or environment must be **[explicitly enabled](https://deno.land/manual/getting_started/permissions)**
- **Supports TypeScript out of the box**
- **Ships a single executable** : No separate package-manager, like _npm_
- **Built-in utilities** : [test runner](https://deno.land/manual/testing), [code formatter](https://deno.land/manual/tools/formatter), built in [debugger](https://deno.land/manual/tools/debugger), dependency inspector and [more](https://deno.land/manual/tools)
- **Bundling** : Scripts can be [bundled](https://deno.land/manual/tools/bundler) into a single JavaScript file
- **Standard modules** : Audited and [guaranteed to work with Deno](https://github.com/denoland/deno/tree/master/std)

## Executing JavaScript/TypeScript

Deno being a single executable file, not needing a separate package-manager or `package.json`-file, an example of a **working HTTP server application** looks like this:

```
import { serve } from "https://deno.land/std@0.50.0/http/server.ts";
for await (const req of serve({ port: 8000 })) {
  req.respond({ body: "Hello World\n" });
}

```

There is **no need to install anything** beforehand or add any configuration-files. **All you need to run is** :

```
deno run example.js

```

Since the code is executed in a sandbox, which is secure by default, the **explicit access must be granted** for the fetching the remote dependency, by adding the flag `--allow-net` to the command-line.

The remote dependency is **cached locally** and only reloaded if the script is executed with the flag `--reload`.

## Limitations

Deno 1.0 [has some known limitations](https://deno.land/v1#limitations), which include things like:

- No automatic compatibility with existing npm-packages
- HTTP server performance is not as good as Node.js, even if it's not too far away
- TypeScript performance issues

Since Deno uses ECMAScript modules, which uses `import` instead of `require`, any module using `require` has to be converted.

## Summary

**I'm surprised at how excited I am about the potential of Deno.** For me, to have the creator of Node.js use a decade of learning to start over with a blank slate is what makes this a rare situation of high potential.

Some things I look forward to from Deno are:

- A fresh take on a JavaScript/TypeScript runtime
- First Class TypeScript Support
- Skipping `package.json` and `npm install` when you just want to get started fast
- Promises as default: Avoiding callback hell and mixed concepts between different parts of the code
- Not having to deal with the `node_modules`-folder