Deno - Successor of NodeJS? Deno vs Node comparison

    • stunntech blog author image
    • Bivin Vinod

  • |
  • May 28, 2020

Deno is a new runtime for JavaScript and TypeScript, created by Ryan Dahl - the original creator of Node.js. The project is intended to fix some design problems in NodeJS.

 

Currently, the project has over 150 contributors. Besides the release of the 1.0 version, there is a plan to provide a command-line debugger and built-in code linter to improve the developer experience. Deno should also serve HTTP more efficiently.

 

Deno uses ES Modules as the default module system, whereas Node.js uses CommonJS. External dependencies are loaded using URLs, similar to browsers. There is also no package manager and centralized registry, modules can be hosted everywhere on the internet. Contrary to Node.js, Deno executes the code in a sandbox, which means that runtime has no access to the network, the file system and the environment. The access needs to be explicitly granted, which means better security. Deno supports TypeScript out of the box, which means that we don’t need to manually install and configure tools to write TypeScript code. Another difference is that Deno provides a set of built-in tools, like a test runner, a code formatter and a bundler.

 

The goal of Deno is not to replace Node.js, but to offer an alternative. Some of the differences are quite controversial and it’s hard to predict if they will format in a correct way. I recommend that all Node.js programmers keep an eye on this project. I’m not sure if this project will be a success, but it’s a great opportunity to observe how Node.js could have been implemented differently.

 

Main advantages of Deno

  • Well designed module system.

  • More security.

  • Supports TypeScript out of the box (to surface more typing errors at compiling time).

  • Ships a single executable.

  • Built-in dependency inspector and a code formatter.

 

Main comparisons with NodeJS

  • Deno’s core was written in Rust programming language and Tokio ( the asynchronous run time for Rust), while Nodejs was in C++. As we know that Rust is focused on performance and safety, especially on safe concurrency. And provides more memory safety without using a garbage collector.we can assume that deno is more secure than nodejs.
  • Deno uses Typescript which is the superset of javascript. It gives confidence to a programmer during development by eliminating the development errors much before code execution. As a result the developer can identify the errors before the application starts. And Typescript is good for large application capabilities.
  • The main noticeable difference between deno and nodejs is that Deno completely uses ES6 import statements as dependency management. Which is a decentralized approach.
  • Deno does not use npm - modules are references are file path or urls. These modules can be hosted on our own servers. Eg: import * as log from "https://deno.land/std/log/mod.ts"; So it does not use any package manager like npm or yarn and also does not have package.json for module handling.
  • Deno will always break on unhandled exceptions unlike NodeJS.
  • Deno requires explicit permissions for file, network, environment access. Files are being executed inside a sandbox, so it has no access to the file system. There is a prompt for asking permissions when you run a .ts file. Eg: fetch.ts: const result = await fetch("https://deno.land/"); Allow net calls to any host/url: $ deno run --allow-net fetch.ts

 

Basically its an upgraded NodeJS or can be called as Node V2. And we can expect a more stable version of deno which will be used for enterprise-grade applications development in the near future.