What is Deno and should we start learning it?

A comparison with Node.js

Credits: deno.land

Hello Everyone!

There is a new hype in the JavaScript world which is the introduction of Deno. Well you can of course visit their official page here https://deno.land/ to look in to the documentation. In this article I will discuss how Deno is different from Node.js and answer the question “Will it replace Nodejs?”.

Deno was created by Ryan Dahl, the same person who created Node.js. Deno can be defined as an anagram for Node. When you visit their official website, the landing page quote states Deno is “A secure runtime for JavaScript and TypeScript” and there you have the first difference. Deno lets you run TypeScript at ease which Node.js lacks (Or involves some steps to do so). Lets get some hands on with Deno to understand this statement better

You can install Deno in any one of the following methods (Link: https://deno.land/)

Deno installation (Credits: Deno.land)

After installation you can start Deno by simply typing “Deno” from your command prompt

Deno and Node in CMD

As we can see both Deno and Node opens an interactive prompt for performing calculations. But they can do more than that. Lets consider a simple Node.js code

Simple server code in Node.js

The above code will display “Hello World!” in the browser, specifically on “http://localhost:3000/”. Also Node often works with packages like Express.js where we have to install the packages and maintain the package.json file to keep track of them. But lets see how Deno uses it

Typescript execution in Deno

You can run Deno files using the command

Output from the Typescript code

As you can see Deno supports TypeScript without the need of external compilation, instead the compiler is built into Deno. Now lets create a simple server with Deno just like in Node. I’ll use the same code provided in their documentation

Simple server code in Deno

We can see that Deno imports it’s modules not from any “node_modules” folder or through any built in imports instead it downloads the module directly from the link provided at the time of compilation and caches it locally so it need not download every time when we use that import again. Deno also allows top level awaits as in for plain promise functions, as opposed to Node.js which allows only Async level awaits. When you run the code you will face the following error

This is because, Deno promises a secure runtime where you can spin up a server only when you explicitly set the “- -allow-net” flag like this

Where in Node.js you can spin up servers without any restrictions. This is a critical security feature in Deno which prevents third party libraries from compromising your system under the hood. This security feature is set by default restricting permission for network access and so on.

As a summary, Ryan tried to address the problems which he considered are regrets about Node.js . You can check out the entire video of his “10 Things I Regret About Node.js” here https://www.youtube.com/watch?v=M3BM9TB-8yA. He has successfully addressed quite some regrets he talked about like improved security, getting rid of node_modules and package.json and a new way to import modules.

Deno team promises to maintain a stable API. Where the general API will not change with future versions and they also suggest it may or may not be the right choice depending on your application need. Another important note to take away is that Deno is not yet compatible with npm packages, which is a disadvantage for now but it might change in the future. In the end, Deno can be a replacement to Node.js. We can say it does the same functions as Node.js but in a better way so to say. However, Deno is just out of the incubator (Version 1.0 released on May 4, 2020) and their official documentation suggestions many features are still not stable or it’s work in progress. This doesn’t mean that Node.js is gonna shut their doors. Ryan himself clarified this in his talk “Deno is a New Way to JavaScript” here https://www.youtube.com/watch?v=1gIiZfSbEAE. Anyway, play around with Deno and let me know if you find anything interesting.

Thank you and Happy learning!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store