Deno vs Node

Have you heard a lot of hype about Deno and pondered to yourself some of these questions →

  • What is Deno?
  • Is it the next big thing?
  • Will it replace Node?
  • Should I learn Node or just jump to Deno?

Well, we can check the differences between both of them and then you can decide for yourself.

But first, let’s see what are the similarities between them both.

Similarities

✦ The first and the most important similarity is their creator, Ryan Dahl .

Deno was created by Node’s creator Ryan Dahl . Ryan found several design problems in Node which he highlighted in his very famous conference talk 10 Things I regret about Node.js . He attempts to correct them in Deno.

Fun Fact: Deno is just an anagram of Node.
> 'node'.split('').sort().join('')
'deno'

✦ Both of them are JavaScript runtimes which use V8 engines to execute Javascript codes. Although, Deno also has in-built support for Typescript.

✦ Deno and Node have a similar development model of event-driven architecture and asynchronous non-blocking tools to build web servers and services.

These were just some brief topical similarities between the two. More similarities do exist between the two due to a high-level likeliness in their purpose but these were enough to let you have a basic idea about the two.

Let’s move to differences now.

Differences

✦ Deno has built-in support for both Typescript and Javascript and does not need the developer to manually install and configure tools to write Typescript code, unlike Node.

✦ Deno does not need package.json or dependency list. Interestingly, it has no use for NPM at all. This is a massive architecture change from Node. Deno uses ES6 import style to include modules in the code via URL.

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

In other words, Deno loads external dependencies using Browser. It has no central registry which means the modules can be hosted anywhere. The modules are downloaded, compiled, and cached when the application is first run thereby eliminating the need to download again and again. Therefore, Deno also does not need package.json file or a dependency list.

Node uses CommonJS module system where modules where included in the following manner →

const express = require('express')

Security is a major advantage in Deno .

Deno is executed in a sandbox ! That means it does not have permission to interact with anything at all until you give it permission to do so thereby increasing security.

Example: The following is a basic code from Deno’s official website

import { serve } from "https://deno.land/std@0.61.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" });
}

Try running the code by this command →

deno run app.ts

It won’t run! But why though?

Because it does not have access to the internet and therefore cannot download the package or even “serve” the port 8000.

You need to provide permission to access the internet by using a flag as follows →

deno run --alow-net app.ts

This time the code will run but the interesting thing is that the app only has permission to access the internet and not other things like the file system. You can get a list of permission in Deno here .

✦ NodeJS is internally based on C++ whereas Deno is based on Rust(syntactically similar to C++ but provides better memory safety and concurrency performance. Again, Security! )

Wow, all these benefits! Shouldn’t I immediately switch to Deno?

Well, Deno is not production-ready yet and is still under development having been just introduced recently in 2018. And according to Ryan Dahl, Deno is not here to replace Node but to provide an alternative. In his own words,

Use Node. Node isn’t going anywhere. Deno is under development and Node is a very stable software and is going to be around for a long time.

So you shouldn’t worry about your Node.js skills becoming redundant with the introduction of Deno, but rather view it as an interesting new skill and keep an eye on its effect on the tech market.

Conclusion

Ryan Dahl created Deno in order to solve the design problems that existed in Node according to him. Deno supports both Typescript and Javascript and has better security, therefore it might be interesting to see how it rises amongst others. Node, however, is very stable and is still one of the most popular and therefore isn’t going anywhere for a long time. Deno is just a new thing for enthusiasts to be excited about 😇.

Please comment your feedback below.

Happy Learning!