Deno — The Successor to NodeJs !

Gautam Paul
8 min readSep 27, 2020
Deno Vs Node

If you observe carefully, DENO is an anagram of the word NODE. But probably much more than that as you start exploring it.

In 2018, Ryan Dahl, the original creator of Node.js, gave the famous talk “10 Things I Regret About Node.js” and announced his new project — Deno. He said, Deno aims to fix Node.js design mistakes and offers a new modern development environment. It has come a long way since then. Just yesterday, their twitter handle announced the release of version 1.4.2 with bug fixes.

Deno is a very modern, secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust. The basic documentation for Deno is available on doc.deno.land.

Node is written in C++ and JavaScript but Deno is written in Rust and TypeScript. Deno’s best advantage is that it can afford to have everything re-written with modern technologies, since there’s no backward compatibility to maintain. Sounds very liberating!

Default TypeScript Support

If you love TypeScript, dislike millions of npm packages in your projects and can live without await, Deno is just what you’re looking for!

Deno has TypeScript at its core, which brings a huge advantage in many different ways including a first-class TypeScript support. Running TypeScript code with Deno does not require a separate compilation step as Deno does that automatically for you.

Also the tools you use can infer many information about Deno as it is written in TypeScript. This means that while we code in VS Code, which obviously has a tight integration with TypeScript since both are developed at MicroSoft, we can get many benefits like type checking while coding and advanced IntelliSense features. The editor is very helpful many different way.

Very Secure

Deno has a sandbox based security model at its core that prevents programs from doing anything other than what you allow. Deno also tries to replicate the same permission model that all the browser currently implement. No JavaScript running in the browser can do less secure things on your system unless you explicitly allow it.

Also if a program want to access the network, then we need to give it explicit permission. You can achieve this by passing a flag when running the command.

deno run --allow-net app.ts

Some more useful flags are below:

  • --allow-env allow environment access
  • --allow-hrtime allow high resolution time measurement
  • --allow-net=<allow-net> allow network access
  • --allow-plugin allow loading plugins
  • --allow-read=<allow-read> allow file system read access
  • --allow-run allow running subprocesses
  • --allow-write=<allow-write> allow file system write access
  • --allow-all allow all permissions (same as -A)

A Single Executable File

Deno comes with a single executable with no dependencies. You can install it using the installer commands or download a release binary from the releases page.

$ brew install deno

Unlike the modular binaries in Node.js, Deno is a single binary application. It also does not make use of the complex dependency management solutions like the NPM. Instead, developers declare dependencies in source code using direct URLs. There are already huge third-party Deno modules available. This approach is yet to be tested to scale large enterprise applications. As a result, Deno is in general not compatible with NPM packages written for Node.js.

In addition to TypeScript and JavaScript, Deno applications can load and execute WebAssembly bytecode programs. A common example is the Sqlite module in Deno. It is compiled from C++ to WebAssembly. Also developers could extend Deno with Rust. This further allows the Rust dependency/package manage system — Cargo, to be used to manage Deno plugins and add-ons.

Built-in Utilities

The Deno standard library is very young but its still very extensive. It includes many useful tools like:

  • archive tar archive utilities
  • async async utilities
  • bytes helpers to manipulate bytes slices
  • datetime date/time parsing
  • encoding encoding/decoding for various formats
  • flags parse command-line flags
  • fmt printing & formatting
  • fs file system API
  • hash crypto lib
  • http HTTP server
  • io I/O lib
  • log logging utilities
  • mime support for multipart data
  • node node.js compatibility layer
  • path path manipulation
  • ws websockets

It also provides built-in tools like a test runner, a code formatter and a bundler.

Formatter

Deno has built-in utilities like a dependency inspector deno info and a code formatter deno fmt , just like Go, that automatically formats the script and adds semicolons if omitted anywhere.

$ deno fmt index.ts

Audited Standard Modules

Deno provides a curated list of audited standard modules that are reviewed by the Deno maintainers and are guaranteed to work with a specific Deno version. These reside alongside the Deno source code in the denoland/deno repository.

These standard reviewed modules are hosted at deno.land/std and are distributed via URLs like all other ES modules that are compatible with Deno.

These modules listed above do not have external dependencies and they are reviewed by the Deno core team. The idea is to have a standard set of high quality code that all Deno projects can use fearlessly.

These modules will eventually be tagged in accordance with Deno releases but as of today we do not yet consider them stable and so we version the standard modules differently from the Deno runtime to reflect this.

No Package Manager

Deno does not use the CommonJS format and doesn’t provide a package manager like npm. All modules are loaded directly in code using just an URL.

Hello World Example

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

If you want to run the program again, it’s now cached by Deno and it does not need to download it again. You may force a reload of the original source with the --reload flag.

There are some advantages of using the Deno style. By importing code via URL, it’s possible to host modules everywhere and anywhere on the internet. Deno packages can also be distributed without a centralized registry and avoid any corporate control. There is also no need for the package.json file and a dependency list, because all modules are downloaded, compiled and cached on the application run. This helps to remove the dependency on a centralized registry like npm for Node.js which is now controlled by Microsoft.

Third Party Modules

Deno can import modules from any location on the internet, like GitHub, a personal web server, or a CDN like AWS, Skypack or jspm.io. This can also do away with the monopoly of a controlled registry.

As Microsoft is tightening its grip around open source projects, it could allow Microsoft to dictate the policies around these open source projects in future. When Microsoft acquired GitHub, many open source developers moved to alternate platforms like GitLab though GitHub remains the first choice for the developers.

To make it easier to consume third party modules, Deno also provides some built in tooling like deno info and deno doc. Also deno.land provides a simple public hosting service for ES modules that work with Deno. It can be found at deno.land/x. Basically deno.land/x is a hosting service for Deno scripts. It caches releases of most open source modules stored on GitHub and serves them from one domain.

For example — lodash, a modern JavaScript utility library delivering modularity, performance, & extras can be found here : lodash@4.17.19

Embraces ES Modules

As you all know, Node uses the CommonJS syntax for importing packages. Deno uses ES Modules but the official way. It uses modern ECMAScript features in all its API and standard library, while Node.js only uses a callbacks-based standard library and has no plans to upgrade it.

First Class Await

With Debo, we can use the await keyword without wrapping it into an async function because Deno implements top-level await. When using async/await in Node.js, you will have to wrap the await inside of an asynchronous function, and you have to label it async. Deno makes it possible to use the await function in the global scope without having to wrap it inside an async function which is an awesome feature.

Browser Compatible

Deno has always aimed to be browser-compatible as far as possible. It provides a built-in fetch and the global window object. The built-in fetch implementation matches the one available in the browser currently.

Deno highly supports V8 Inspector Protocol which makes it possible to debug Deno programs using Chrome Devtools or other clients that support the protocol like VS Code. To activate debugging capabilities, please run Deno with flags like--inspect or --inspect-brk
— inspect flag allows attaching a debugger at any point in time, and
— inspect-brk will wait for debugger breakpoint and pause execution on the first line of code.

Built-in Testing Support

Deno has a built-in test runner that allows us to test our JavaScript and TypeScript code. The syntax is very similar to the one used by JavaScript testing libraries like Jest or Jasmine.
You can simply use the test functionality on the Deno namespace to create a test. We can then run our tests with the deno test command. With the testing module, you can run a full test suite by pointing your deno test command to a test suite hosted somewhere online without having to pull down and run the test suite yourself.

Popular Library Availability

Deno also provides support for very popular libraries and middle-wares which NodeJs has used thus far. Some are listed below:

  • deno-drash — A REST micro framework for Deno’s HTTP server with zero dependencies
  • deno-express — A solution to run a Deno Webserver like the node express way
  • oak — Oak is interesting because it’s inspired by Koa
  • pogo — Pogo is an easy-to-use, safe, and expressive framework for writing web servers and applications and is inspired by hapi
  • servest — A progressive http server for Deno

Also Deno has a compatibility layer with the Node.js stdlib in progress.

Cloud Support

Deno has just reached v1.0 but is already supported by notable players in cloud computing industry, like major cloud providers such as AWS Lambda, Azure Functions and Google Cloud Run.

Conclusion

Finally the big question — Will it replace Node.js?

May be not today as Node.js is a well established giant with incredibly well supported technology. The prominent goal of Deno is not to replace Node.js, but to offer an alternative for the next tech generation. Right now, some of the differences are quite controversial and it’s very hard to predict if they will work out in a feasible way. But all Node.js programmers should closely monitor this project.

While most are optimistic about Deno’s future, but majority of developers believe that Node.js is here to stay. It will be very formidable for Deno to overtake Node.js in the present day due to the large ecosystem and enterprise applications around Node.js.

But there is always a David that kills the Goliath.

--

--

Gautam Paul

Engineering Director / Software Architect / Writer