Getting Started With Deno!

At Mediform we've been moving our server side stack to Deno. Deno is a modern runtime for JavaScript and TypeScript with a focus on security. Deno supports TypeScript out-of-the box, ships as a single executable and it has a number of built-in utilities like a compiler formatter and a linter.

In this post I will introduce you to Deno through a tutorial. By the end of this tutorial you will have setup a Deno development environment in Visual Studio Code and created a standalone Hello, World application served over HTTP.

🦖 Setup

Deno comes as a single executable that can be used for building, testing, linting and formatting. The Deno executable can run as an interpreter for TypeScript or JavaScript. It can be used as a Run-Eval-Print-Loop (REPL) interactive shell and it can compile TypeScript or JavaScript to a self contained executable.

The Deno executable contains a V8 JavaScript engine that is used for all JavaScript execution. It also contains a TypeScript compiler and a number of built in library functions including File access, Fetch and an HTTP Server.

Since Deno ships as a single executable installation is easy. There is an installer project and Deno is available through many different package managers, but if you're just getting started, you can just download the single executable. Unlike Python, Node or Java, installing multiple versions of Deno is simple -- just download multiple versions of Deno. There are no paths that must be configured, no registries to edit and no shared libraries to manage.

To get started with Deno, either follow the instructions on the Installation Page, or download the pre-built binary for your system from the Latest Release.

To use the REPL interactive shell, type deno. Hello-Deno

🔧 Tool Support

Deno provides an official VSCode Extension powered by the Deno Language Server. The language server is part of the Deno executable, so no other dependencies are needed. Once the extension is installed, your workspace can be configured as a Deno project by using the Deno: Initialize Workspace Configuration from the command pallette. Deno-VSCode

Since Deno can execute TypeScript directly, there is no need for a build or transpile step. All Dependency management is done through import statements, removing the need for an install step.

For example, to create a program that generates random names using a Random Name Generator, you can simply reference the library from your TypeScript file and execute it directly in VSCode.


🔗 Standard Library

Deno includes a powerful standard library with no external dependencies. The Deno standard library was heavily influenced by the GoLang standard library. There are utilities for managing collections, encoding and decoding text, cryptography APIs, filesystem operations, a powerful webserver and more.

In addition to the standard library, hosts a large collection of Third Party Modules. Third party modules include everything from a Lodash port, to Middleware modules, to powerful argument processors.

In future posts we will look at many of the library functions available and dive into how to use them.

🎉 Hello, World

Finally, we will use the basic HTTP Serer that ships with the standard library to create and serve a Hello, World! application.

// main.ts
import { serve } from "";

const port = 8080;

const handler = (): Response => {
  return new Response("Hello, Deno World! 🦖", { status: 200 });

console.log(`HTTP webserver running. Access it at: http://localhost:8080/`);
await serve(handler, { port });

To run this application, use deno run --allow-net main.ts. The --allow-net flag enables the application to access the network interface to start the webserver. We will look at other permissions in a subsequent article.