blur code

Blur Code

Working towards providing new and cool programming articles.
A perfect blend of knowledge & technology to become a better coder

Deno: Will it replace NodeJS?

Deno 1.0, a javascript runtime environment just got introduced with some cool new features and a lot of advancements. Take a deep breath and let's dive into Deno and try to learn what Deno really is!

Rishit Pandey

5 minute read

So all the javascript developers and web developers use NodeJS for compiling javascript apps with electron or for backend development. Since its been a decade when the NodeJs was introduced, we have witnessed various changes in javascript and code writing practices especially ECMAscript changes, that made javascript to compete with other high level languages such as Rust, Python and so on. This article is all about knowing what Deno is, how is it different from NodeJS and will it replace it. Let’s take off!


What is NodeJS?

Source colorlib
Source colorlib

NodeJS is a Javsascript runtime environment. Okay but how does it work?

Node.js came into existence when the original developers of JavaScript extended it from something you could only run in the browser to something you could run on your machine as a standalone application. It helps you to run javascript natively on your machine and use javascript runtime rather than needing you to run it on the browser. It is based on C++ and Google Chrome’s V8 Javascript Engine but on steroids.

Here is the formal defination as provided on the official NodeJS site:

Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.

Node.js’ package ecosystem, npm, is the largest ecosystem of open source libraries in the world.

Well yeah, you heard it right. NodeJS’ package manager has over 350,000 as counted on 2017.


So now what is Deno?

Deno is also a Javascript runtime environment but is built using Rust and Google Chrome’s V8 Engine. It is developed by the same person who developed NodeJS. Deno overcomes the limitations that NodeJS had like security issues, huge build system, bulky node_modules, and many more. Deno provides a faster and more secure runtime environment for modern javascript developers. Deno has a lot of advantages when compared to NodeJS and other javascript runtime environments. For example, it uses javascript promises rather than callbacks to fasten the runtime enviroment.

Source typeofnan
Source typeofnan

>Security

Deno by default executes your code in a sandbox so if something goes wrong, it will not harm your system and will not have permissions to access your file system and the environment variables. This is very much useful to the developers working on their js applications or backend stuff.

>Built-in Package Manager for Resource Fetching

Unlike NodeJs where you had to use a seperate package manager npm for installing and managing javascript frameworks, Deno plays a role of both runtime and a package manager and makes it easier to manage your frameworks and removes the need of the bulky node_modules folder.


>Modules

In Deno there is no package manager so how do we use libraries and frameworks? Well, the answer is just like you use bootstrap! Deno provides you with a unique url for each package and there is no need to install them natively and for each app.js. Deno helps it easier to import node modules using import/export instead of using require() and asssigning it to the variables.


>TypeScript support

Deno has a built-in TypeScript support so the developers don’t have to globally install any packages or linting scripts to support TypeScript.

>Permission to perform actions

Deno by default has no permission to access machine’s file system and other environment variables and so it always requires permission for that. It also does not allow the random and inconsistent native functions to be bound in the V8 JavaScript. System calls are done by message passing by only two native functions — send and recv — it makes the design simpler and easier to analyze.


Deno: Give it a lick!

Want to try how Deno and know how Deno works?

Deno comes only with a single executable with no dependencies. If you are on a mac or linux:

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

If you are using Windows, you might want to use Chocolatey or Scoop(which make it easier to manage packages on Windows), and then run:

When using Chocolatey:

:-$  choco install deno

When using Scoop:

:-$ scoop install deno

Rocking mac with Homebrew? Here you go:

:-$ brew install deno

Or if you want to go the hard way clone this repo and build it from source!


Welcome to the Deno Land!

So now that you have installed Deno let’s have a shot at it.

Run this on your terminal:

:-$ deno run https://deno.land/std/examples/welcome.ts

or a more complex one:

import { serve } from "https://deno.land/std@0.53.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
  req.respond({ body: "Hello World\n" });
}

The Conclusion

The final conclusion on this will be whether or not Deno will replace NodeJS. Short: Honestly, No. Long: Imo, not atleast in 2-3 years. This is because at the moment Deno doesn’t have support for most of the node packages and to implement that it will take atleast a year or two to support all of the packages. Another thing that lets down Deno is that it is in early days of its development. The developers have just released Deno 1.0. Deno will probably take off when all of the javascript or typescript developers will be familiar with Deno and Deno will have support for all of the node packages, or atleast most of them.


Reviews

If You find it interesting!! we would really like to hear from you.

Ping us at Instagram/@the.blur.code

If you want articles on Any topics dm us on insta.

Thanks for reading!! Happy Coding

Recent posts

Categories