Getting Started with Deno

Written by Preston Lamb

Posted on Feb 8, 2021

javascriptdeno

Getting Started with Deno

Learn how to start using Deno with my brand new course!

Buy the Course

tldr;

Deno is a runtime for JavaScript and TypeScript, much like Node.js. It is built on modern web standards, with the same APIs that you have in the browser. It is new but its future is bright. In my new video course, you will get hands on experience so you can be ready to use Deno for your applications and projects. It's great for those who have never heard of Deno but want to get started, or for those who have a little bit of experience with it but want to sharpen their skills. Over the course of the 29 videos, you will get a lot of hands on practice using many of the capabilities of Deno. The rest of this article will give you an overview of Deno and prepare you for the course. Then, click here to buy the full course!

What is Deno?

Deno is a runtime for JavaScript and TypeScript. Its 1.0 release came in May 2020, with a goal to be secure, web compatible and use modern features wherever possible. The ideas and goals of Deno are a result of a desire to improve upon existing JavaScript runtime options. JavaScript has been around for many years, and has been growing in popularity. This has resulted in a desire for better options of writing and running JavaScript code. In addition, new features or additions to the language can be slow to be adopted with older runtimes and frameworks. For example, TypeScript's adoption has grown a lot over the last couple years, but there still isn't a simple, out-of-the-box option for it being used in Node.js. In Deno, that's not the case. Developers can choose to use JavaScript or TypeScript, whichever they would like. The goal is to allow developers to use the best tools for the job. Options like this assist in writing stable applications that can stay viable long term.

Benefits of Deno

Now that you have an understanding of what Deno is, when would you use it? Deno can be used in many ways. One would be as a replacement for writing utility scripts that would normally be written in bash or python. Another option would be as a replacement for Node.js when writing JavaScript or TypeScript applications. The size and scope of the application don't limit where Deno could be used. Before selecting Deno, though, let’s take a look at some of its benefits:

  • It has been built with security by default. There is no access to the file system, network, or environment information by default. All that access needs to be given explicitly when the application is run. If you haven’t given your application access to the network, you don’t have to worry about it using the network. The security issues that arise in Node applications, for example, should be limited in Deno applications.
  • It can bundle your application to a single JavaScript file to be run wherever you deploy your application.
  • It supports TypeScript out of the box. There’s no need to use any extra tools to compile your TypeScript. Just create a file with a .ts extension and you are good to go. In addition, you can mix JavaScript files and TypeScript files in your program. While you will likely choose one language for your application, third party scripts may come in both JavaScript and TypeScript. There’s no need to worry about this in your application.
  • It comes with several utilities and tools that are provided for your use. Some of those tools are a bundler, a formatter, a linter, and a documentation generator. These are all part of the command line interface that’s provided after installing Deno on your machine. There's no need to waste time choosing these tools on your own because they come provided for you.
  • There is a standard library, which contains packages that can be used for many common tasks. Some examples are datetime, which eliminates the need for Moment.js, date-fns, or similar libraries; and log and colors which eliminate the need for chalk.

These are just some of the benefits of using Deno. They'll be covered in more depth throughout the book.

Differences Between Deno and Node.js

Before selecting Deno, it may help to look at some of the differences between Deno and Node. Here are some of those differences:

  • It does not use npm. Dependency management is handled differently than you’re used to with your Node (and other JavaScript) applications. This means there is no package.json used for determining external modules. Modules are included by URL or file paths local to the project.
  • It uses “ES Modules”, and thus does not support “require()” when bringing in external modules to a file.
  • Deno requires explicit permission for network access, file access, and environment access. This prevents unwanted access being granted to malicious third party packages.
  • It always dies on uncaught errors. The consistency of behavior is beneficial when writing applications.

This is just a starting point of the benefits of Deno and its differences with Node. As you go through this book, you'll learn more about those benefits and differences. By the end of the book you should be able to make an informed decision on your choice of technology. You should also be on your way to effectively working with Deno while writing your scripts and applications.

Deno Architecture

One more thing before we continue: in this book we won't be going into detail on the architecture of Deno. It's good to know, though, that Deno uses V8 (a JavaScript engine maintained by Google) to execute JavaScript. It is also built in Rust. One of Rust’s many advantages is its focus on security. Security was a high priority in the creation of Deno, so Rust was a great choice for building Deno. If you'd like to learn more about the architecture decisions for Deno, you can check out the Deno Lib GitBook.

Getting Started with Deno

Learn how to start using Deno with my brand new course!

Buy the Course