Will Deno replace Node Js?

Akarsh Barar
6 min readMay 18, 2020
Deno

What is Deno?

Deno is a runtime general purpose JavaScript/ Typescript programming environment. It is created by Ryan Dahl, yes you got the name right he is the creator of NodeJs. Deno is created using Rust programming language.

You might be thinking why Ryan created a language that can take over his own created language, this is just because some years before Ryan faced some problem regarding packages manager, this might be the reason why deno came into existence.

Main focus of Ryan while creating NodeJs was to make a language which is heavily focused on event Driven HTTP servers. Some issues faced by Ryan in NodeJs are:-

  1. Not Sticking with promises, Promises are the abstraction for async/await. Promises were added in Node in 2009 but in 2010 it was removed. Its possible unified usage of Promises in node would have speed the delivery of the eventual standardization and async/await. Now a days there are many async API are aging badly due to this.
  2. Security: Node app are not secure unlike python , javascript is itself very secure. But Node has zero security if you write a single script it can exploit your whole server.
  3. The Build System: One of the biggest regret is the build system. Build system are very difficult but very important for building projects. The Build System uses GYP, It is a Compiler to integrate code from another language to Node. But currently chrome shifted from GYP to GN making Node the only single user of GYP. V8 Engines are not built more with GYP but it has wrapper for GYP. Instead of guiding user to write C++ binding for V8 it should be provided a core foreign function interface(FFI).
  4. Package.json: Its the life line of any javascript project. Package json file was then introduced with NPM that made it defacto standard. Require is specific it has to be defined many placed. Allowing Pacakge json gave rise to concept of module as a directory of files.
require
Node modules

5. Node Modules: It has massively complicated algorithm for naming node modules.

6. No Extension: Needlessly less explicit. The module loader has to query the file system multiple location trying to guess what the user intended. You need to be pro while designing file structure.

7. Index.js : There was no need of index.js.

Deno has built in support for Typescript it means it has support for javascript too. In terms on security it is secure by default this you can get from the tag line of Deno ie

Deno : A secure runtime for JavaScript and TypeScript.

Deno also has inbuilt ECMAScript modules.

You can never understand everything. But you should push yourself to understand the system. -Ryan Dahl

TypeScript

You can use typescript with deno it means you can use javascript too. Best thing is that it has its own Config file so you don't need to add tsconfig.json file in your project but you can add you own by writing deno run -c tsconfig.json. It is very easy to run ie if you have any deno file so you can just change the extension to ts and it will run. It does everything internally thats the cool thing about deno.

Security

Its secure by default as the tag line says.

What does that mean?

So if you want to run a deno file you just cannot run anything directly you have to give permissions to it prior running any file. Like if we run without any permission deno run abc.ts, it will give error like uncaught Permission denied. This was done just to make sure your system is secure. Permissions are used for

  1. Environment Access
  2. Network Access
  3. File System handling
  4. Running sub-processes

Deno has Decentralized Package Manager as in node app we have npm packages that are internally dependent on another package here we don’t have that. We don’t have any folder like node module.

import { serve } from "https://deno.land/std@0.50.0/http/server.ts";

This download the data and stores locally or in cache for the further use.

Promise/async/await

Promises have native data binding for async. So in node we use async along with await but in deno we can just use await without use of async.

Standard Library

As deno is decentralized it has collection of standard library for use. Deno additionally gives a rundown of evaluated standard modules that are checked on by the Deno group and are ensured to work with a particular Deno variant. These live close by the Deno source code in the denoland/deno repo.

These standard modules are hosted at deno.land/std and are distributed via URLs like all other ES modules that are compatible with Deno.

Deno can import modules from any location on the web, like GitHub, a personal webserver, or a CDN like pika.dev or jspm.io.

DEMO

I am using VSCode for this demo make sure to have below extension installed to avoid in errors

Deno in extension

To install you can use any of the given below options:

Using Shell (macOS, 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 Cargo (Windows, macOS, Linux):

cargo install deno

Using Homebrew (macOS):

brew install deno

Using Chocolatey (Windows):

choco install deno

Using Scoop (Windows):

scoop install deno

My Way as I use Linux so here it is choose according to your Operating System

Installing on Linux

As our deno is installed lets go with the example

In the above code we can see that we have allowed net permission thats why it is able to download if it was not given it has shown me error. The above code is of server running at 8000.

localhost:8000

Conclusion

As Ryan already find such issues in Node js, It does not mean Node js is dead it depends on your work and preferences, what you like how you work with it.

If you want me to write a blog fully on Deno and its usage please comment.

REFERENCES

  1. https://www.youtube.com/watch?v=M3BM9TB-8yA

2. https://deno.land/

3. https://www.youtube.com/watch?v=HjdJzNoT_qg

4. https://www.youtube.com/watch?v=zFf_fcn0cI0&t=48s&pbjreload=10

If you want to ask any question or want to suggest any topic ping me on Instagram.

Make sure to subscribe to my YouTube Channel :

https://youtu.be/yWSdXqf_2k4

And follow on Instagram:

@mycodecave

Also on Facebook :

https://www.facebook.com/CodeCave-299370007293562

You can join my whatsapp flutter group the link is in the bio of instagram.\

--

--