Deno is a new framework from the creators of NodeJS. In this post, we will look at what is Deno and the step-by-step approach of getting started with Deno.

The creator of NodeJS Ryan Dahl built Deno as an answer to improve upon NodeJS. Similar to NodeJS, Deno can also be used for server-side JavaScript. However, Deno tries to rectify some of the mistakes or issues with NodeJS. You can think of it as a sequel to NodeJS.

1 – What is Deno?

Deno is a Javascript runtime. Apart from JavaScript, Deno also supports Typescript and WebAssembly runtime.

Deno is built using the V8 engine similar to NodeJS. Also, it uses Rust programming language internally.

2 – Features of Deno

Some of the important features of Deno are as follows:

  • Deno supports both JavaScript and Typescript as first-class languages at runtime. Choosing to use one or the other language is a matter of putting the correct file extension. This benefits Deno because Typescript has steadily gained popularity over the years.
  • Deno attempts to be as web-compatible as possible. In other words, a Deno application should work in the backend as well as in the browser. At the end of the day, Deno is just executable JavaScript or Typescript. It aims to be future-ready.
  • Deno is also secure by default. Basically, there is no out-of-the-box access to the file systems, network or the environment until and unless the developer has enabled it. Basically, this prevents malicious use of Deno scripts.
  • Deno ships with a standard library containing many in-house utility functions. This makes Deno a bit more opinionated while providing more tools to the developer. This modules are guaranteed to work in a typical Deno runtime.
  • Unlike NodeJS, Deno does not use a package.json file.

Ultimately, Deno aims to be a productive and secure scripting environment for the modern developer.

Deno will always be distributed as a single executable. If we provide a URL to a Deno program, it is runnable with the executable.

Deno explicitly takes on the role of both runtime and package manager. It uses a standard browser-compatible protocol for loading modules: URLs.

Also, Deno is a great replacement for Bash or Python utility scripts.

3 – Deno Installation

We can install Deno on MacOS, Windows and Linux depending on our requirement.

The easiest way to install Deno on a Mac or Linux is by using the below command:

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

For Windows (powershell), we can use the below command.

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

There are other installation mechanisms using Homebrew or Chocolatey. However, the above two are probably the easiest methods to getting started with Deno.

After the installation is complete, we can verify the same using the below command.

$ deno --version
deno 1.24.0 (release, aarch64-apple-darwin)
v8 10.4.132.20
typescript 4.7.4

If the version number is shown, this means the installation is upto the mark.

Now, we can start creating our first Deno application.

4 – Creating a Deno Application

To create a Deno application, we will first create a source directory.

$ mkdir deno-app
$ cd deno-app

Next, we create a file index.ts or index.js within the directory and simply place a console statement. As you can see, we can use JavaScript or Typescript out-of-the-box.

console.log("Hello, World Deno");

And this is basically your first Deno program.

We can run this program using the below command.

$ deno run index.ts

This will print the greeting message on the screen. Our program works fine.

Congratulations, you now have a working Deno setup and a basic program you can build further.

Conclusion

As you can see, getting started with Deno is quite easy. It has even lesser steps than NodeJS. Also, it provides great flexibility in terms of the programming language we are comfortable with.

Deno is quite promising in its mission statement and it will be interesting to see if it catches up in the industry.

You can read more about Deno on the official website.

If you have any comments or queries about this post, please feel free to mention them in the comments section below.

Categories: BlogDeno

Saurabh Dashora

Saurabh is a Software Architect with over 12 years of experience. He has worked on large-scale distributed systems across various domains and organizations. He is also a passionate Technical Writer and loves sharing knowledge in the community.

0 Comments

Leave a Reply

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