Deno Hello World

Deno programs are written in JavaScript/TypeScript.

Deno is a runtime for JavaScript/TypeScript which tries to be web compatible and use modern features wherever possible. This means that a program in Deno is the same as the one you can run in the browser.

In this tutorial, you will be taught how to write your first Deno program, we are also going through examples on how to create a Deno project.

Your First Deno Program

Your first Deno program will be a simple Hello World. Follow the steps below to create your program:

Step 1

Open your favorite editor or IDE. We will be using Visual Studio Code throughout this tutorial, and create a new file named hello.js you can save it inside your Documents folder for easy access.

Step 2

Enter the following JavaScript code in the hello.js file.

console.log("Hello Lyty!");

and save it.

Step 3

Run the code with Deno. Open your terminal (Ctrl + Option + Shift on macOS or Ctrl + Alt + T on Ubuntu on or Ctrl + Shift + Enter on Windows (Powershell)) and navigate to the folder where hello.js is located. For the purpose of this tutorial we are navigating to ~/Documents/ with cd ~/Documents, after navigating, run the code below:

deno run hello.js

Or From VS Code

Go to the Menu bar and select 'View' then select 'Terminal' this display the terminal already navigated to the directory where the file is located, then run the code below:

deno run hello.js

Deno Hello World Program

console.log(new Date());
  Do It Yourself

Creating a Deno Project

A project is a collection of related files and folders in one main folder for a specific application.

To work on a specific application, you will always want to create a project as this application might have more than one file associated with it.

To create a Deno project, follow the steps below:

Step 1

Create a folder called hello inside your Documents or My Documents folder (you can create this anywhere, we are creating it inside Documents to make it easily accessible). 

Open your project with your favorite code editor or IDE. 

To open with Visual Studio Code on Linux, in your terminal, navigate to the project folder by typing cd ~/Documents/hello,

Deno project navigate to project folder

then open the folder with VS Code typing  code . this opens the hello project on VS Code.

Deno project Navigate Success

Step 2

In the project folder (hello), we will create a new file called hello.js , you can easily to that from the VS Code editor or any other one.

Deno projec create new file

You also do that on a Linux terminal: touch hello.js

In the file, type in the code below:

console.log("Hello Lyty!");

and save it.

Step 3

In your terminal run:

deno run hello.js

Live Example Your First Deno Program

console.log('Hello Lyty!');
  Do It Yourself

You have successfully created a Deno project.

The 'Next Chapter' teaches how to use Deno as a web server.

What Should Know At The End Of This Chapter

  • You should be able to create a run a Deno program from your terminal.
  • You should know what a Deno project is and must be able to create one project.
  • Get familiar with your favorite Code Editor or IDE as editors may not be explained again in later chapters.