What is Deno and will it replace Node.js?



Good day. I present to you the translation of the article “Deno vs. Node.js - Here are the most Important Differences ” by Louis Petrik.

Is Deno the new Node.js? Or just a good alternative? In this article I will try to answer these questions.

History of Deno


Deno and Node.js are the workings of one person - Ryan Dahl.

Dahl has been working on Node.js since 2009, but after a few years left the team. In 2018, he made a presentation, “10 Things I Regret About Node.js.” In this talk, Dahl introduced Deno - a new “engine” for JavaScript and TypeScript.

Fun fact: “Deno” is an anagram of “Node.”

Should developers be afraid that Deno will replace Node.js in the near future?

Dahl himself believes no.



Link to the video.

As Dahl notes in his speech, Deno is still inferior to Node.js in completeness (stability).

However, both are JS code runtimes outside the browser, for example, on a web server. But hardly anyone can say how the "relationship" between Node.js and Deno will develop in a few years.

Deno and Node.js: internal device


Node.js is written in C ++ and uses V8 to execute JS code. V8 was specifically designed for Google Chrome to run JS code in the browser as quickly as possible. Currently, almost all browsers, including Microsoft Edge, have switched to V8.

Deno is also based on V8, but instead of C ++, it uses Rust, a language whose goal is not only good performance not inferior to C ++, but also security: eliminating memory access errors or buffer overflows.

Security is one of the main drawbacks of Node.js, because after launching the application, it gains access to the file system or network.

Deno tries to fix this by asking the user for permission to access.

A good example is the following TS code from Deno's official website:

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

const s = serve({ port: 8000 })

for await (const req of s) {
	req.respond({ body: 'Hello World\n'})
}

As you can see, this is a very simple web server that starts like this:

deno run app.ts

However, since Deno is not granted permission to access the network, we get the following message:



To provide access, we need to do the following:

deno run --allow-net app.ts

Now our server is working. But the application will not have access to the file system until we allow it.

Goodbye NPM, hello ES6 import


Another security issue for our applications is NPM: not only does the use of NPM create a huge “node_modules” folder, but also installed packages that make the application work can theoretically contain malicious code.

Deno does not use NPM, instead, libraries are imported via URL, as shown in the example.

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

The library is loaded on first run and cached:



This is similar to how we copy the code for our web server and store it separately on the server or computer for reuse. Libraries do not need to be reloaded.

Window object outside the browser


Window is a global object in the browser containing some very important JS functions.

One such feature is fetch. Fecth cannot be used in Node.js - there are special libraries for this, but in Deno it can.

This is due to the fact that Deno has access to Window, as follows from the documentation .

The following code can be run in both the browser and Deno:

fetch('https://jsonplaceholder.typicode.com/todos/1')
	.then(response => response.json)
	.then(data => console.log(data))

TypeScript support out of the box


Using TypeScript is, of course, a matter of taste. Some like it, others don't. Be that as it may, Deno supports TypeScript out of the box and, of course, it also supports JavaScript.

You can verify this by writing code, saving the file as .ts or .js, and running it with deno run. In my opinion, this is not a significant advantage, since TypeScript support can easily be added to Node.js.

Thank you for attention.

All Articles