Getting started with Deno JS

Getting Started With Deno – Deno.js Tutorial

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

Getting Started with Deno – Intro

In simple words, deno is a secure runtime environment for both javascript and typescript. It is built on top of V8, Rust, and TypeScript and developed by Ryan Dahl.

V8 is an open-source JavaScript engine developed by The Chromium Project for Google Chrome and Chromium web browsers.

Rust is a multi-paradigm programming language focused on performance and safety, especially safe concurrency.

Deno Highlights

Initial release 13 May 2018
Stable release 1.2.0 / July 13, 2020
Preview release 1.0.0-rc3 / May 12, 2020
Original author Ryan Dahl
Operating system Linux, macOS, Windows
Written in TypeScript, JavaScript, Rust, C++

Deno Features

The features provided by deno as per the official website are:

  • Deno is secure by default, we need to explicitly provide access.
  • Supports typescript out of the box.
  • Works well with standard modules.
  • Has built-in utilities like deno info and deno fmt.
  • It ships only a single executable file.

Installing DenoJS

Installing deno JS is quite a simple process. Deno ships as a single executable with no dependencies.

There are two ways for installing deno js.

  1. Using Binaries
  2. Using Commands

Using Binaries

You can download a release binary from the official deno releases page.

Using Commands

Shell (Mac, Linux):

$ curl -fsSL https://deno.land/x/install/install.sh | sh

PowerShell (Windows):

$ iwr https://deno.land/x/install/install.ps1 -useb | iex

For the complete set of commands, please refer 👉 https://deno.land

First Deno JS program

Now, since we have successfully installed deno, let us run our first piece of code using deno js.

The file welcome.ts is a typescript file with a simple console message “Welcome to Deno 🦕” and is hosted on deno land website.

We will directly run that file from our PowerShell command prompt.

$ deno run https://deno.land/std/examples/welcome.ts

Installing Deno and Running the first program: 

Getting Started with Deno

DenoJS using VSCode

Now, let’s write a bit complex code using one of our favorite code editor – VS Code. In case if you don’t have VS Code installed on your machine, get it from code.visualstudio.com, it’s free 🙂

Let’s open the VS Code, create a file named “hello.js” and paste the given code(taken from deno.land).

import { serve } from "https://deno.land/std@0.63.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
  req.respond({ body: "Hello World\n" });
}

Now, running this code we would expect “Hello World” as output into the browser window.

[Solved] Uncaught PermissionDenied Error

While running our program using,

deno run hello.js

We got this error:
Uncaught PermissionDenied: network access to “0.0.0.0:8000”, run again with the –allow-read flag

Why this error while running our first piece of code?

Deno is secure by default. Therefore, unless we specifically enable it, a deno module has no excess to file, network, or environment. So, we need to grant permission explicitly.

–allow-net  – For accessing the net

–allow-read – For reading files

–allow-write – For writing files

For our code, in order to solve this error, we need to pass the additional flag “–allow-net” along with deno run command.

deno run --allow-net hello.js

This will run our program and ask us to navigate to http://localhost:8000/ using the Ctrl + Click.

Deno JS Hello World

Summary

Let’s summarize all our learning with respect to getting started with deno js.

  • Deno is not a replacement for node js.
  • Deno is a secure runtime for both JavaScript and TypeScript.
  • If you’re using typescript extensively then using deno.js you may get rid of your extra javascript compilers like babel.
  • Deno does not use npm nor does package.json.

If you are stuck somewhere, please refer to the deno manual for more information.

Getting Started With Deno – Courses

These two courses look good to me for deno.js concepts.

1️⃣ Deno: The Complete Guide Zero to Mastery

3138058 45fe

 

2️⃣ Mastering Deno.js: Beginner to Expert [2020]

3293408 3513 3

 

Getting Started With Deno – Youtube

This video explains the basics of deno.js in 5 minutes and helps you in Getting Started With Deno. You may check it out and subscribe to the channel.

Deno Tutorial

If you are looking for step by step tutorial on denojs, then you may refer to our tutorial space.

👉 Deno Tutorial – Getting Started With Deno

PS: If you found this content valuable and want to return the favor, then Buy Me a Coffee at ko-fi.com

You may follow us on Instagram, for amazing posts.

I hope that you like this post on Getting Started with Deno JS. Please share it with your friends and help us grow our reach.

Disclaimer: Most of the content is FREE. But some resources may contain affiliate links. When you purchase, I may receive a commission from the seller, at no extra cost to yourself.

Share with your friends:

Leave a Comment

Your email address will not be published. Required fields are marked *