Getting Started with Deno 🦕

Chris Bongers - Aug 6 '20 - - Dev Community

Today, we'll be covering getting started with Deno! Deno is a JavaScript server language like node.js but built in Typescript.
It's designed to improve the shortcomings of node.js.

It's been quite hyped over the last couple months, and even when writing this article, I have zero experience with it, so this guide is also my guide.

What is TypeSript?

As mentioned, TypeScript is a superset of JavaScript. TypeScript is a strongly typed language, meaning types must be defined when declaring variables. This makes it more strict and easier to spot errors and faults.

Setting up Deno

To get started, we need to install Deno locally first.

If you are on Linux/Mac run the following command:

curl -fsSL https://deno.land/x/install/install.sh | sh
Enter fullscreen mode Exit fullscreen mode

If you're on Windows:

iwr https://deno.land/x/install/install.ps1 -useb | iex
Enter fullscreen mode Exit fullscreen mode

Note: You can find your install package on the Deno website

You can verify the installation by running:

deno --help
Enter fullscreen mode Exit fullscreen mode

Our First Deno Application

So let's start by creating our first Deno application.

Create a new folder and our starting file server.ts

mkdir deno && cd deno
Enter fullscreen mode Exit fullscreen mode

Let's start adding lines to our server.ts file

import {serve} from 'https://deno.land/std@0.63.0/http/server.ts';
Enter fullscreen mode Exit fullscreen mode

This tells our server to import the serve module from a URL; in node.js we would have to use npm install first!

Now we are going to create a new Deno server:

const server = serve({port: 1337});
Enter fullscreen mode Exit fullscreen mode

We are starting our server on port 1337.

Sending a response to the browser

for await (const req of server) {
  req.respond({body: 'Hello Deno!!'});
}
Enter fullscreen mode Exit fullscreen mode

So this is a bit different then what we see in node.js.
We loop through each incoming request, and for each request, we are returning a body!

Running Our Deno Server

To run our deno server, we can run the following command in our terminal.

deno run --allow-net server.ts
Enter fullscreen mode Exit fullscreen mode

Now we can open our browser and go to localhost:1337. We should now see our body!

Awesome, getting started was really quick and easy!

You can download my starter project on GitHub

Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player