Is Deno the new Node.js ?

Anand Prasad
5 min readMay 19, 2020

Hello world ! So recently the creator of node.js, Ryan Dahl launched Deno v1.0 after he confessed “10 things I regret about node.js” on June-6-2018 at JSConf Berlin in his 26 minutes speech. Let’s get started.

Ryan Dahl talked about about many flaws about Node.js in his speech. The list follows :-

  • Not Sticking with promises.

Ryan communicated that he added promises/rejection in June 2009 but foolishly removed them in February 2010 and promises are necessary abstraction for async/await, stating the process should be minimal (if you are familiar with node.js syntax) and the ecosystem could have been much faster. It’s possible that unified usage of promises in Node would have speed the delivery of the eventual standardization, and async/await many async API’s are doing badly due to this.

  • Security.

JavaScript v8 engine is a very secure sandbox unlike python. He stated more security can be provided by node.js and should have some nice security guarantees not available in other languages. Example: Your linter shouldn’t get complete access to your computer and network.

  • The Build system (GYP)-Such a pain !

After stating “the build system” he added such a pain !! Node uses this thing called GYP (If a writing a module that links to a c library you use it to link in node).Chrome used GYP, but later dropped for GN leaving node a solo GYP user.It’s exposed to anyone who uses GYP and It’s an awful experience for users.

  • package.json

package.json is like the life blood of JavaScript this time.Every module is dependent on package.json file so it’s necessary to maintain the package. Allowing package.json gave rise to the concept of a “module” as a directory of files. package.json now includes all sorts of unnecessary information. License? Repository? Description? It’s boilerplate noise.

  • node_modules — Heaviest objects in the Universe

It massively complicates the module resolution algorithm and becomes complex overtime. It really deviates greatly from browser semantics.

  • require(“modulename”) without the extension .js …. why ??

Needlessly less explicit. You have to be a pro in file system for that.

  • index.js

He thought it was cute, because there was index.html :P .It needlessly complicated the module loading system. In contrast to the focus on evented I/O early on, the module system was essentially an afterthought. With this mind he thought it could have been better. ……….

Hello Deno !

On May 13, 2020, same Ryan Dahl introduces a new language and calls it “Deno v1.0” which has overcome the flaws in node.js

Deno is a secure runtime for JavaScript and TypeScript and has already gotten popular having more than 57k stars and 2k forks on github becoming more popular among the developers. Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust. As deno official landing page states :

  • Secure by default. No file, network, or environment access, unless explicitly enabled.
  • Supports TypeScript out of the box.
  • Ships only a single executable file.
  • Has built-in utilities like a dependency inspector (deno info) and a code formatter (deno fmt).

Deno resolves almost every problem stated by Ryan in node.js

Goodbye require statements :)

The biggest problem resolved was require statement from node.js Now Deno does not need any require module imports rather it uses just an URL to import any files/modules.The reason of introducing deno rather than upgrading node.js was it may be not backward compatible like python 2 and python 3 environment.

Installing deno…

Inbuilt TypeScript and JavaScript compiler :)

Journey of a deno land starts from a single typescript file. As you have relieved from require statements , now you don’t need to install typescript or javascript compilers it’s embedded in deno. In this file we have access to all the types at runtime. We can get strongly typed code and still get intellisense without ever needing to touch tsconfig.json. ex. printing the current working directory in deno land : console.log(Deno.cwd()). “Deno is secure by default”

Goodbye Callback hell :)

Security is great but the favourite thing is how everything asynchronous is promise based. We can make a network request using fetch API without any extra boilerplate code just like we are in the browser because it supports top level await we don’t need any async function here.

Browser Compatible :)

Deno attempts to make the code as browser friendly as compatible, it contains a window object with life cycle events that we can listen to which make developers to easily write code b/w browser and servers.

npm packages :)

npm packages !!! We don’t do that here. Instead we import packages from modern es6 syntax with remote modules be referenced by URL. At first attempt it download it to your local machine. just like…..

no more package.json

Hello World in Node.js vs Deno

  • Creating a simple “Hello World” server in Deno land
Hello World server in Deno
  • vs a “Hello World” server in node.js
Hello World server in node.js

Will Deno replace Node.js ?

Well can’t say, but you are on the safe right now because there are many projects running on node.js by several MNC’s and big organization so it’s difficult to shift the project on other platform and replace the old source code. Moreover Deno is in under audit and may have some bugs and flaws.

Thank you for reading this article, I hope it added to you knowledge. Please leave a clap if you like :)

You can never understand everything. But, you should push yourself to understand the system.

~ Ryan Dahl

Thank you :)

--

--