“Hello world!” app with Deno

Poornima
3 min readOct 20, 2020

This article is aimed for beginner developers and anyone interested in getting up and running with Deno. Before diving into this article, you should be confident enough with JavaScript to know the basic concepts of the language. Technical terms regarding Deno will be explained and linked below.

What is Deno?

A secure runtime for JavaScript and TypeScript.

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

Installation

Deno works on macOS, Linux, and Windows. Deno is a single binary executable. It has no external dependencies.

Download and install

deno_install provides convenience scripts to download and install the binary.

Using Shell (macOS and Linux):

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

Using PowerShell (Windows):

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

Using Scoop (Windows):

scoop install deno

Using Chocolatey (Windows):

choco install deno

Using Homebrew (macOS):

brew install deno

Using Cargo (Windows, macOS, Linux):

cargo install deno

Deno binaries can also be installed manually, by downloading a zip file at github.com/denoland/deno/releases. These packages contain just a single executable file. You will have to set the executable bit on macOS and Linux.

Testing your installation

To test your installation, run deno --version.

If this prints the Deno version to the console the installation was successful.

Use deno help to see help text documenting Deno's flags and usage.

A detailed guide on the CLI here.

Updating

To update a previously installed version of Deno, you can run:

deno upgrade

This will fetch the latest release from github.com/denoland/deno/releases, unzip it, and replace your current executable with it.

You can also use this utility to install a specific version of Deno:

deno upgrade --version 1.0.1

Start your text editor of choice and create a file named helloworld.js.

Let’s write some code.

/* helloworld.js */function capitalize(word) {
return word.charAt(0).toUpperCase() + word.slice(1);
}
function hello(name) {
return “Hello “ + capitalize(name);
}
console.log(hello(“john”));

Run the app with following command

deno run helloworld.js

In the above JavaScript example the message Hello [name] is printed to the console and the code ensures the name provided is capitalized.

Output

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS C:\Users\mpradeep\Deno> deno run helloworld.js
Hello John

TypeScript

TypeScript example below is exactly the same as the JavaScript example above, the code just has the additional type information which TypeScript supports.

create a new file with the extension *.ts helloworld.ts

/* helloworld.ts */function capitalize(word: string): string {
return word.charAt(0).toUpperCase() + word.slice(1);
}
function hello(name: string): string {
return "Hello " + capitalize(name);
}
console.log(hello("john"));

The deno run command is exactly the same, it just references a *.ts file rather than a *.js file.

Run using following command

 deno run helloworld.ts

You have successfully created your first Denoapp. Don’t stop here, keep exploring the wonderful world of Deno, as it has much more to offer.

Found this article helpful, feel free to follow me for more articles like this. If you believe this article will be of big help to someone, feel free to share.

Happy coding :)

--

--

Poornima

Full stack Developer- I help aspiring and established web developers take their coding skills to the next level.