Deno: The Beginner's Guide

Deno: The Beginner's Guide

Learn about the new JavaScript and TypeScript runtime called Deno, which aims to solve some flaws in Node.js and introduce a few different concepts.

Learn about the new JavaScript and TypeScript runtime called Deno, which aims to solve some flaws in Node.js and introduce a few different concepts.

JavaScript is the best language for those who want to learn to program, and it really has made a huge impact on people’s lives.

On the other side, Node.js has helped JavaScript take over the world of web development. It has introduced a lot of new developers to the programming world and made it easier to build modern applications, spend less time figuring out how to work with JavaScript properly and build better and more robust applications.

Since the release of Node.js back in 2009, it has really come a long way. With new features and concepts implemented inside Node.js, it’s improved the way we work with JavaScript. But, like any project, it has some things that we wish were better and we could improve.

The Problem with Node.js

Ryan Dahl, the creator of Node.js, gave a talk in 2018 called “10 Things I Regret About Node.js.” In this talk he explained what he wished he’d done differently. For those who want to learn more about the initial concepts of Node.js, this is a great talk.

The essential idea behind the creation of Node.js was to focus on programming event-driven HTTP servers. Here are some the things that Ryan Dahl regrets about Node.js:

1) Promises

Promises were introduced as part of the ES6 (ES2015) and landed in Node.js only in February 2015. They’re very important, especially due to the async/await primitives that came up in Node.js in February 2017.

The possible usage of Promises when Node.js was developed would contribute to the eventual standardization of async/await. They’re a necessary abstraction for async/await.

2) Security

This is an important and highly discussed point about Node.js. It was built on Chrome’s V8 JavaScript engine, which is a very good security sandbox. But we still have some problems with security in Node.js, especially with giving access to packages that shouldn’t have access to our computer and network.

3) node_modules

The _node_modules_ folder contains libraries downloaded from npm. Every time we start a new project, we need to install new dependencies, and by doing that, our _node_modules_ folder gets heavier and heavier.

Unfortunately, there’s no way to undo this in Node.js. Dahl said that “it’s impossible to undo now.”

4) package.json

The package.json file is a common file created at the root directory of a Node.js module by running a command. There are a few things that he regrets about package.json, and one of the things is that the package.json file doesn’t allow relative files and URLs to be used when importing—the path defines the version. By doing that, there would be no need to list dependencies.

He also listed as regrets: the Node.js Build System (GYP), index.js (when you include a directory, it looks for a file called index.js) and the point where you don’t need to include the “.js” extension to require a module, which turns into a mistake because this is not how browser JavaScript works.

Deno

After realizing all the points that he wished could be better in Node.js, Dahl revealed in his 2018 talk that he was creating a new secure JavaScript runtime called Deno.

Deno is a new secure JavaScript and TypeScript runtime released this May 13. It brings a lot of functionalities and JavaScript features, with a more secure and powerful core.

Here’s how Deno is different from Node.js:

Rust

One of the programming languages that has been trending in the development community lately is Rust. This language has been very popular for a lot of factors, such as ensuring that our programs are free from undefined behavior and data races, more memory safety, etc. Rust is a very safe and fast language.

Node.js is based on the V8 engine to execute JavaScript, and the V8 is based on C++. The difference here is that Deno also is based on the V8 engine to execute JavaScript, but is also based on Rust.

A safer and faster language makes a big difference for Deno—delivering a good performance, without any memory safety issues, undefined behavior, data races, etc.

Security

One of the issues a lot of developers complain about in Node.js is security. The choice of using Rust was not only right for allowing the runtime to be faster and bug-free, but also to improve the security. After an app starts running, it can easily access your file system or your network—this is a very serious security flaw.

Deno solves the security by executing the code in a sandbox. The runtime has no access to your file system or network. Unless you specify that you want to enable or disable access, a module has no file, network or environment access. Instead, you can use command-line arguments to enable or disable different security features or do so programmatically.

For example, if we want to grant read-only access for a file, we could do the following:

deno run --allow-read test.ts

TypeScript

Deno is a JavaScript and TypeScript runtime, which means that it brings TypeScript support by default. We can easily use TypeScript anywhere in our code without having to install or transpile anything.

Deno only requires qualified modules names, which means that we should include the extension of the file when importing it. Imported modules are specified as files in Deno.

import main from "./main.ts";

ES6

Deno includes a built-in package manager for resource fetching, so there’s no need to use npm (Node Package Manager).

This can be a huge change in the way we build modern JavaScript applications. Instead of downloading packages from the npm repository, we just pass a URL, and Deno loads for us the dependencies, similar to browsers.

Deno uses the official ECMAScript module standard rather than the CommonJS. Deno uses the import syntax from ES6 instead of the require() standard.

Another nice thing about Deno is that you cache all the modules that you download. So, if you download a module, Deno will automatically cache it, and not download it again, only if specified with the reload flag.

deno javascript typescript node developer

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Top 5 Reasons Javascript Developers Prefer Deno Over Node

Why Deno is exactly what a back-end Javascript developer needs in 2020. Let’s take a look at the top 5 reasons javascript developers are having a much smoother and more modern experience using Deno vs. Node. The maker of NodeJS, Ryan Dahl, has released a new runtime that aims to solve many of the shortcomings of Node. Your initial reaction might be “Oh great, another Javascript framework? Just what I needed…”.

What is Deno and is Node.js Dying? | Deno vs Node

What is Deno? Deno vs Node. Is Node.js going to die? Deno is a runtime for JavaScript and TypeScript that is based on the V8 JavaScript engine and the Rust programming language. It was created by Ryan Dahl, original creator of Node.js, and is focused on productivity. It was announced by Dahl in 2018 during his talk "10 Things I Regret About Node.js"

Deno, a Secure Runtime for JavaScript and TypeScript

What is Deno? Deno is a runtime for JavaScript and TypeScript that is based on the V8 JavaScript engine and the Rust programming language. It was created by Ryan Dahl, original creator of Node.js, and is focused on productivity. It was announced by Dahl in 2018 during his talk "10 Things I Regret About Node.js"

Introduction to Deno: A Secure JavaScript & TypeScript Runtime

What is Deno? Deno is a JavaScript and TypeScript runtime. Should you forget Node.js and start learning Deno? What are the difference between Deno and Node? Deno programs can access resources on the host computer, such as the filesystem and environment variables.

Deno vs. Node: A Good Crisp Difference Between Node and Deno

Deno vs. Node: A Good Crisp Difference Between Node and Deno - Here is a basic tutorial on a crisp difference between Nodejs and Deno. Before starting with Deno it good to understand what problem deno solves.