What is Deno and Will it replace Node.js?


What is Deno?

Deno is a runtime for JavaScript and TypeScript based on the JavaScript V8 engine the same as the Node.js, and it is created by the same person as the Node.js, Ryan Dahl. Deno was announced by Dahl in 2018 during his talk "10 Things I Regret About Node.js". Deno aims to be a productive environment for the modern programming, like Node.js it is an event-driven architecture, with a set of non-blocking IO utilities, along with their blocking versions. Deno is used mostly for creating web servers. You can check the talk by Ryan Dahl on Youtube on the link below:

deno 10 Things I Regret About Node.js - Ryan Dahl - JSConf EU

Deno Web Server Example

Let's see how does Deno look in some very simple code samples:

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

As you can see we can use TypeScript out of the box with Deno (you can still use JavaScript), next interesting thing is that we can use the import syntax (if you worked with React or some modern JavaScript you should be familiar with it), and as we can see we don't need to install npm modules to import them, instead of with Deno we can import from URL. On the 4'th line, we can also see more modern JavaScript features that Deno is using like promises or async iterable (this is a for loop that goes through an infinite array of incoming events).

You can find more info and documentation about Deno on Deno.Land

Deno Comparison with Node.js

As we said Deno and Node.js are both runtimes that are built on the V8 engine, the same engine used for Google Chrome. Both Deno and Node.js have internal event loops and provide a command line for running scripts. Deno is different from Node.js in the following aspects:

  • Uses ES Module as the default module system, instead of CommonJS.
  • Uses URLs for loading local or remote dependencies, similar to browsers.
  • Includes a built-in package manager for resource fetching, thus no need for NPM.
  • Supports TypeScript out of the box, using a snapshotted TypeScript compiler with caching mechanisms.
  • Aims better compatibility with browsers with a wide range of Web API.
  • Allows a control to file system and network access in order to run sandboxed code.
  • Redesigns API to utilize Promises, ES6, and TypeScript features.
  • Minimizes core API size, while providing a large standard library with no external dependencies.
  • Using message passing channels for invoking privileged system APIs and using bindings.

Source: Wikipedia


Will Deno replace Node.js? Deno is a replacement for Node.js, BUT! not in the sense that you should start learning it and using it right away, instead you could look at Deno because it might do the same thing as Node.js but on a better way. Deno is still in the early stages of development, and Node.js is used in many projects out there, this means that Node.js is not going out of the game anytime soon.

#deno #javascript #typescript

Author: Aleksandar Vasilevski |