Author -  Sai gowtham

A beginners Guide to Deno - Secure runtime for JavaScript

In this tutorial, we are going to learn about what is Deno and how to getting started with it.

What is Deno?

Deno is a secure runtime for executing the JavaScript and TypeScript outside the browser environment. Which is built on top of V8, Rust, Tokio (event loop), and TypeScript.

If you know about Node.js creator Ryan Dhal, the same person is created Deno with the similar goals that Node offers to us.

Features of Deno

  • Secure by default, it means deno doesn’t allow you to use, network, file access, or environment access unless you need to enable explicitly.

  • It supports modern JavaScript features like es modules and top-level await.

  • First-class TypeScript support, so that we can use typescript in our apps without any extra tooling.

  • Deno is distributed as a single executable file.

  • It has some built-in tools for bundling the modules and formatting the code, etc.

Installing the Deno

Let’s install the deno, by running the following command inside your terminal.

curl -fsSL | sh

deno installation

Have you seen, inside the terminal you are seeing some instructions like in the above screenshot?

According to the instructions, we need to add the following paths inside the .bash_profile or .zhsrc file.

export DENO_INSTALL="/Users/saigowtham/.deno"

To verify the successful installation, you need to run deno --help command in your terminal.

If it shows the following output then you are successfully installed deno on your machine.

~ deno --help
deno 1.0.0
A secure JavaScript and TypeScript runtime


To start the REPL:

To execute a script:
  deno run

To evaluate code in the shell:
  deno eval "console.log(30933 + 404)"


    -h, --help
            Prints help information

    -L, --log-level <log-level>
            Set log level [possible values: debug, info]

    -q, --quiet
            Suppress diagnostic output
            By default, subcommands print human-readable diagnostic messages to stderr.
            If the flag is set, restrict these messages to errors.
    -V, --version
            Prints version information

    bundle         Bundle module and dependencies into single file
    cache          Cache the dependencies
    completions    Generate shell completions
    doc            Show documentation for a module
    eval           Eval script
    fmt            Format source files
    help           Prints this message or the help of the given subcommand(s)
    info           Show info about cache or info related to source file
    install        Install script as an executable
    repl           Read Eval Print Loop
    run            Run a program given a filename or url to the module
    test           Run tests
    types          Print runtime TypeScript declarations
    upgrade        Upgrade deno executable to given version

    DENO_DIR             Set deno's base directory (defaults to $HOME/.deno)
    DENO_INSTALL_ROOT    Set deno install's output directory
                         (defaults to $HOME/.deno/bin)
    NO_COLOR             Set to disable color
    HTTP_PROXY           Proxy address for HTTP requests
                         (module downloads, fetch)
    HTTPS_PROXY          Same but for HTTPS

Getting started

Open your terminal and run the deno command to start the REPL (read-execute-print-loop).

➜  ~ deno
Deno 1.0.0
exit using ctrl+d or close()
> 1+2
> console.log('hi deno');
hi deno

to exit the repl use ctrl+d or close() command.

Writing our first deno program

Let’s write our first hello world program using deno.

For this, we need to create a new directory called deno-examples.

mkdir deno-examples
cd deno-examples

Now, open the directory using your favorite code editor (mine is vscode) and create a new file called index.js then add the following code.

const a = "Hello world";

To run our program, we need to use the deno run command followed by the file-name.

deno run index.js


➜  deno-examples deno run index.js
Hello world

Creating the HTTP server

Let’s create a simple HTTP server using Deno.

Create a new file called server.js and add the following code.

import { serve } from ''

console.log('server is running on port 3000');

for await (const req of serve({port: 3000})) {
    req.respond({ body: '<h1>Welcome to deno land</h1>' });

In the above code, we first imported the server function from the deno http standard module.

Inside the for loop, we are responding to the requests we got on localhost:3000.

Now, run the program using deno run server.js.

Deno starts downloading the http module and its related dependencies then it caches in your system (so, you can use this module when you are offline).

➜  deno-examples deno run server.js
error: Uncaught PermissionDenied: network access to ":3000", run again with the --allow-net flag
    at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
    at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10)
    at Object.listen ($deno$/ops/net.ts:51:10)
    at listen ($deno$/net.ts:152:22)
    at serve (
    at file:///Users/saigowtham/deno-examples/server.js:4:25

At the last, we see an error related to network access.

This error has occurred because our code is executed in a secure that by default scripts don’t have permission to access the file system or opening network connections.Unless we need to explicitly give the permissions.

To give the above program a network access, we need to pass a --allow-net flag to the command.

deno run --allow-net server.js


➜  deno-examples deno run --allow-net server.js
server is running on port 3000

Now, open your browser and navigate to localhost:3000 you will see a h1 element is rendered on the screen.

deno server is running

Dependency inspector

Deno has a built-in dependency inspector by using that we can view the dependency tree of our programs.

Let’s see the dependency tree of our server.js file by running the below command.

deno info server.js

Now, you can see the following output in your terminal.

➜  deno-examples deno info server.js
local: /Users/saigowtham/deno-examples/server.js
type: JavaScript
    │ ├─┬
    │ │ ├─┬
    │ │ │ ├─┬
    │ │ │ │ ├──
    │ │ │ │ ├─┬
    │ │ │ │ │ └──
    │ │ │ │ └─┬
    │ │ │ │   ├──
    │ │ │ │   └──
    │ │ │ ├─┬
    │ │ │ │ ├──
    │ │ │ │ └──
    │ │ │ ├─┬
    │ │ │ │ └──
    │ │ │ ├──
    │ │ │ ├──
    │ │ │ └─┬
    │ │ │   ├──
    │ │ │   ├──
    │ │ │   ├──
    │ │ │   └──
    │ │ └──
    │ └──
    │ ├──
    │ ├──
    │ └─┬
    │   └──
      │ ├──
      │ ├─┬
      │ │ └──
      │ └──

Code formatting

Deno also has built-in code formatter to format our code, and also adds missing semicolons to our code.

To use this, we need to run the deno fmt command.

deno fmt

It formats all files in your app.

If you want to format a single file, you need to run deno fmt command followed by the file-name.

deno fmt server.js


Here are some resources, you can learn more about deno.

  1. Deno Manual.

  2. Deno third party modules.

  3. Deno API.

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content