Will Deno kill Node.JS in coming days?

Key things that Deno Brings for developers on the table

XOR
XOR
May 19 · 4 min read
Photo by Sebastian Pociecha on Unsplash

Node.js, something very familiar to developer for over a decade. Does something named Deno replace this super popular runtime in coming days?

Note: Node.js and Deno both are the child of the same father, Ryan Dahl.

He talks about his mistakes with Nodejs here and a more in-depth look into deno here

Deno is something very new for the developers. As introduction

Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust.

Deno logo looks like this.

Deno build on top of

  • V8 as node.js

I have noted installation and some most interesting aspect of this new runtime here.

Installation

Using Homebrew (macOS):

brew install deno

Using Cargo (Windows, macOS, Linux):

cargo install deno

TypeScript by born

Deno supports typescript by default. No fancy setup or configuration needed.

Rest in Peace tsconfig.json

In-built support for typescript i.e you can run typescript files directly without compiling to javascript.

Deno makes it easy to use TypeScript without the need for any config files. Still, it is possible to write programs in plain JavaScript and execute them with Deno without any trouble.


Secure by default

Secure by default. No file, network, or environment access, unless explicitly enabled.

Deno is secure by born. You have to explicitly specify the security like network, environment or any thing like that.

Unlike node, deno run in sand box in host machine i.e

  • No File System Access

So there’s no access from runtime to things like network, file system, etc. When your code tries to access these resources, you’re prompted to allow the action.

Lets try an example

FirstDeno.ts

Now run file by:

deno run FirstDeno.ts

Now the security barrier comes into play

error: Uncaught PermissionDenied: network access to "0.0.0.0:8000", run again with the --allow-net flag
at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10)
at Object.listen ($deno$/ops/net.ts:51:10)
at listen ($deno$/net.ts:152:22)
at serve (https://deno.land/std@0.50.0/http/server.ts:261:20)
at file:///Users/tunvirrahman/Downloads/FirstDeno.ts:2:11

Because Deno is secure by default and you have to explicitly allow network

deno run — allow-net FirstDeno.ts

Here is the available security options to give

--allow-all # Allow all permissions--allow-env # Allow environment access--allow-hrtime # Allow high resolution time measurement--allow-net=<allow-net> # Allow network access--allow-plugin # Allow loading plugins--allow-read=<allow-read> # Allow file system read access--allow-run # Allow running subprocesses--allow-write=<allow-write> # Allow file system write access

RIP Package Manager

Deno doesn’t require any package manager or package.json. Instead it used modern ES Syntax like below

No more package.jsonand node_modules

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

When we start the application, Deno downloads all the imported modules and caches them. Once they are cached, Deno will not download them again until we specifically ask for it with the --reloadflag.

Deno doesn’t supports npm packages. Thats alarming right?

Rather, it has a module management system similar to Go where modules are imported via URL


Promised to be Promise Based

It supports top level await. Everything asynchronous is promise based in Deno.

Bye Bye callback hell

const res = await fetch("https://someUrl")

This doesn’t require the containing method to be async.


Browser compatibility

Deno aims to be browser-compatible. Technically speaking, when using the ES modules, we don’t have to use any build tools like webpack to make our application ready to use in a browser.

However, tools like Babel will transpile the code to the ES5 version of JavaScript, and as a result, the code can be run even in older browsers that don’t support all the newest features of the language. But that also comes at the price of including a lot of unnecessary code in the final file and bloating the output file.

It is up to us to decide what our main goal is and choose accordingly.


Conclusion

Node.js guys. Don't panic. Node is not going anywhere!

If you are writing software from scratch, Deno might be worth investigation. For now it’s for enthusiasts.

Thanks for reading. Cheers 🥂


A note from the Plain English team

Did you know that we have four publications and a YouTube channel? You can find all of this from our homepage at plainenglish.io — show some love by giving our publications a follow and subscribing to our YouTube channel!

JavaScript In Plain English

New articles every day.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

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