Lang
Blog

What is Deno 🦕? Is it the New Node.js?

A New Runtime for TypeScript & JavaScript

ByPayal Mittal
May 22nd . 5 min read
What is Deno? Is it the New Node.js?

Deno is a platform for writing and building applications using JavaScript and TypeScript.

It is created by Ryan Dahl, the original creator of Node.js, to fix the inherent issues of Node.

Ryan first revealed the idea of Deno in a presentation back in the year 2018. After 2 years of continuous work, he finally released Deno 1.0 on 13th May 2020.

It was claimed to be a replacement of beloved Node.js promising high security, bugs fixation, and great developer-experience.

When asked about the need for Deno, Ryan says that- Considering the vast changes in the landscape of JavaScript and the surrounding software infrastructure, building Node projects became an arduous endeavor. It was worthwhile to simplify it. So, we planned to build a fun and productive scripting environment that can be used for a wide range of tasks.

Let’s understand Deno in better terms -

What is Deno?

“Deno is a simple, modern, and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust.”

It is fully compatible with the existing Node.js and has some features that were missing from Node.js.

The building components of Deno are -

  • V8 (Google JavaScript Engine)
  • Rust
  • Tokio platform — provides the asynchronous runtime needed by JavaScript

In the form of Deno, Ryan aimed to provide a secure and more productive scripting environment for the modern community of developers.

Deno plays both roles that of runtime and package manager at the same time and load modules using the standard browser-compatible protocol- URLs.

Deno is a great replacement for utility scripts that may have been historically written with bash or python.

Deno provides a set of built-in tools, such as -

  • Script Installer
  • Code Formatter
  • Bundler
  • Debugger
  • Web-Assembly Generator
  • Docs Generator
  • Test Runner

Deno v/s Node.js

It seems that Deno can become the new next-generation Node.js. While both Deno and Node.js have the same purpose, their working mechanisms differ.

One can say that Deno is the extended version of Node that rectifies all the design mistakes of Node.js and offers a more reliable development environment.

Though both of the platforms share the same architecture (event-driven) and asynchronous tools for building web servers and develop solutions.

The major differences are, however, given as under-

  • While Node’s core was written in C++, Deno’s written in Rust.
  • Unlike Node, Deno uses URLs or file paths to load third-party modules and external dependencies instead of npm
  • While Node uses CommonJS as the default module system, Deno uses ES modules.
  • There is no registry or package.json in Deno. Modules can be hosted everywhere on the internet.
  • Deno needs explicit permissions to get access to files, networks, and environment variables, which means better security.
  • Differing from Node, Deno executes the code by-default in a sandbox which means it has no access to the file system, network, environment variables.

Features of Deno:

Let’s define some of the major features of Deno in detail -

First Class TypeScript Support:

One of the amazing features Deno provides is- it’s support for TypeScript. For complex programs, type checking becomes important and here TypeScript plays its role in providing type information.

Deno allows using of TypeScript without needing config files and external tooling. You don’t need to write the typescript code manually. The transpiration into JavaScript is done internally by Babel or TS compiler.

Integrated Security:

As you can see that Deno doesn’t allow accessing its filesystem, environment variables, network without explicit permission. It keeps you from security risks. Deno uses command-line arguments to enable this access.

If you want to get access to the ‘xyz’ folder, use the command-

deno — allow-read=/xyz myscript.ts

It will allow you to only read from the ‘xyz’ folder. If you want permission to write, you will have to use --allow-write flag. It’s like when you install a new application in your smartphone, it asks permission to get access to your GPS, Contacts, Gallery, etc. The same notion applies here.

Complete & Standard Library:

Deno claims to have a complete library with a set of standard modules that allows developers to perform basic tasks using tools and complex tasks with external libraries.

There are modules for accessing the filesystem, HTTP-related functions, and more. Also, it contains the tools to generate UUIDs, adding color to terminal texts, and working with external data structures.

Stability:

Deno namespace maintains a stable API. Though some features and modules are still not ready for stabilization and they have been hidden behind a –-unstable command-line flag. You can still pass this flag to use these unstable APIs during runtime. But, you must know that these unstable APIs have not undergone a security check and are not ready for production.

All the JavaScript APIs that can interact with the operating system can be found in the ‘Deno namespace’, however, using the namespace means losing browser compatibility.

Fun Fact: Deno is an anagram of Node.

Why Deno?

We are pointing out the most exciting and highlighting features of Deno, that might interest you-

  • Built-in utilities like code formatting (deno fmt), unit testing, dependency inspector (deno info)
  • No package manager, no node_modules. Modules are imported via URL path of the source file.
  • Out-of-box support for TypeScript so, you don’t need to install & configure tools for writing Typescript code manually.
  • Single Executable- ships as a single executable file with no dependencies.
  • Without explicit permissions, no file, environment variable, or network can be accessed.
  • Bundles scripts into a single JavaScript file.
  • It contains a set of audited modules that are guaranteed to work with Deno.
  • Remote code is fetched and cached on first execution, and never updated until the code is run with the --reloadflag.

Installation of Deno:

Let’s get started with installing Deno-

#Using Shell
curl -fsSL https://deno.land/x/install/install.sh | sh
#Using PowerShell (Windows)-
iwr https://deno.land/x/install/install.ps1 -useb | iex
#Using Cargo (Windows, macOS, Linux):
cargo install deno
#Using Homebrew (macOS):
brew install deno
#Using Chocolatey (Windows):
choco install deno
#Using Scoop (Windows):
scoop install deno

Can Deno Replace Node.js in the Near Future?

No. Not now, at least.

It would be a blunt lie, to be frank, to say that Deno can replace Node.js.

It’s a whole new implementation and not a modified version of Node.js, otherwise, it would have been named as just another Node.js version. Perhaps in the future, it may compete with Node.js.

The library of Deno is not stable and some features are not ready yet.

For some purposes, you may use Deno, however, for others, it’s not a good choice though. Not yet.

Even if it is as good as Node.js, it’s still very fresh and new. You can imagine it by the fact that the very first version 1.0 was released just a week ago. So, it may take a while to reap and gain stability.

Final Words -

Though Deno can not replace Node.js, it has some unique features and huge potential. The developer’s community is already very excited to try it out. And the future is very bright and welcoming for Deno.

Thank You for reading!!

Share:
0
+0