DenoJS is a newly introduced runtime announced first in 2018 by Ryan Dahl. It was announced during JSConf EU. NodeJS is also a JavaScript runtime that is there in the market since 2009. Both the tools are basically JS runtimes however there are some key differences between both. In this DenoJS vs Nodejs article, we will discover all those differences.

Let's start with a brief description of both.

NodeJS

NodeJS is an event-driven JavaScript runtime that is used to build scalable applications.

Node can also execute TypeScript code by using ts-node. Ryan Dahl created NodeJS in 2010.

DenoJS

According to the documentation – Deno is a simple, modern, and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust.

Deno is not only a JS runtime but it has inbuilt support for TS as well. DenoJS is also created by Ryan Dahl, the developer and long time maintainer of NodeJS.

You can think of Deno as an improved NodeJS that is a faster, secure, modern tool to build applications.

DenoJS vs NodeJS

First of all, we know that DenoJS is inspired by NodeJS and has addon benefits over it. Now let's talk about the differences between both.

DenoJS vs NodeJS differences

  • NPM is used for NodeJS and it’s the way we install packages and import them in our code. However, DenoJS does not use NPM instead it import packages as URL or file paths.
  • Package.json is necessary for NodeJS applications to maintain and manage dependencies. DenoJS does not use package.json due to its unnecessary boilerplate that includes author, repository, license, etc. Ryan said if only relative files and URLs were used when importing, the path defines the version. There is no need to list dependencies.
  • NodeJS does not stick with Promises. That is the necessary abstraction for async/await. So DenoJS makes sure all async actions in it returns a promise.
  • V8 itself is really good in terms of security. However, with NodeJS there are no such unique addon security benefits. DenoJS requires explicit permissions for the file, network, and environment access. That’s a plus for security over NodeJS.
  • It is not safe to resume normal operation after ‘uncaughtException‘, because the system becomes corrupted. NodeJS does not stop operation after ‘uncaughtException‘. On the other hand, Deno always dies on uncaught errors.
  • In NodeJS we can use require(“module”) to import a module without an extension. That makes it really hard for the module loader to query and find the required module. Deno removes the require() method and uses ES6 imports and third-party modules are imported via urls.

DenoJS vs NodeJS hello world with HTTP benchmark

In terms of performance, we can not decide which one is faster or better just with a single test. So take this as a basic entry point of both and test it with autocannon.

DenoJS application

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

const server = serve({ hostname: "0.0.0.0", port: 8080 });
console.log(`HTTP webserver running.  Access it at:  http://localhost:8080/`);

for await (const request of server) {
  let bodyContent = "Hello world";

  request.respond({ status: 200, body: bodyContent });
}

Add the above code in a file called server.ts. It will create an HTTP server at port 8080 and will return a string “Hello World” with status code 200.

Run the file with the following command.

deno run --allow-net server.ts

NodeJS application

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

The above code is written in JavaScript and can be stored in a file with js extension. It will create a server at port 3000 which will return a plain text “Hello World” and send a status code 200.

Run the file with the following command.

node app.js

Now let's run a simple benchmark with autocannon.

autocannon -c 100 -d 10 http://localhost:3000



nodejs benchmark


autocannon -c 100 -d 10 http://localhost:8080



deno benchmark

The above benchmark was created on the local environment with a quad-core Ryzen processor, 12GB ram, and HDD. According to the benchmark results, we can clearly see DenoJS has less latency as compared to NodeJS except for the Max latency.

The number of requests with DenoJS is much more as compared to NodeJS and also the memory consumption is 61% less for Deno.

DenoJS vs NodeJS popularity

Popularity plays a great role in terms of choosing a tool or framework. The more popular tool we choose the wider community and extensions you can expect.

In this section of our DenoJS vs NodeJS article, we will see how popular is both the runtimes. As both the tools are open source so we will start with GitHub.

NodeJS on GitHub


nodejs popularity

NodeJS has 75.7k stars on GitHub that's really impressive for a mature runtime.

DenoJS on GitHub


denojs popularity

Deno is just 5k stars behind Node in GitHub. However, the number of forks and watch is much less as compared to Node.

Now let's do a search for both on the same platform.


nodejs github



denojs github

We are able to get more than a million results for the keyword node in GitHub. However, with the keyword deno we got only 11,479.

Deno is just launched in 2018 so it's obvious that it will take time for developers to adapt it and build extensions with it.

As of now, NodeJS is more popular than Deno and has a wider community and lots of plugins and extensions to perform many necessary things. So for a beginner, Deno may not be suitable as you have to build thins from scratch.

DenoJS vs NodeJS job market

Deno is still not used widely in production and will take time to make its place in the market. So the job market is almost zero for Deno yet.

The job market of NodeJS is quite good and has a broad scope for freelancers as well.

Reasons to choose Deno

In this DenoJS vs NodeJS article, we have discussed mainly the differences between both. Now let's talk about why Deno and the reason behind it.

Security

Deno is secure by default and you can not access file, network, or environment directly. We need to explicitly enable it.

For example, suppose we want to fetch something as follows. Put this in a file called hello.ts

const result = await fetch("https://deno.land/");

Then we can add a set of domains while executing the program to let hello only establish a network connection to the passed domains.

deno run --allow-net=github.com,deno.land hello.ts

TypeScript support

TypeScript is being used widely among JavaScript developers nowadays. It helps to write better code with type checking, interfaces, classes, etc.

Deno has TypeScript support out of the box.

Single executable file

Deno ships with a single executable file so installing and using it is very quick and flexible.

You can find the installation documentation here.

That's it about DenoJS vs NodeJS. We have learned the core differences of both the runtimes along with the advantages of Deno.

I hope this article has helped you to give a clear overview of reasons to choose Deno or Node. Feel free to share your thoughts in the comment section regarding this DenoJS vs NodeJS article.