Blog

Home / Blog

WHAT IS DENO? A BETTER NODE.JS

Billy Yann
Deep learning and machine learning specialist, well-versed with experience in Cloud infrastructure, Block-chain technologies and Big Data solutions.
March 12, 2020


WHAT IS Node.js?

Built on Chrome's JavaScript runtime, Node.js is a platform that executes JavaScript code outside a browser. Node.js is used to build quick and extensible network programs. As per the official page of Node.js, Node.js is lightweight and efficient as it uses non-blocking I/O model, perfect for applications that run across devices. It allows the developers to use JavaScript to create command-line tools and server-side scripting. Node.js uses the pre-installed package manager npm to manage and organize programs. Node.js works on a single thread event loop that handles the execution of parallel tasks. Even though Node.js works on a single thread it is highly scalable. It buffers no data and delivers in a chunk. The core function of Node.js resides in JavaScript and connects technologies and operating systems.

ISSUES WITH Node.js

One of the major issues with Node.js was that it lacked consistency. The API and compatibility of Node.js kept changing frequently forcing the developers to change the codes within frequent intervals. Even though the modules in Node.js are mature, there are tools in the npm registry that do not serve the purpose. The registry is not well structured and lacks quality coding standards. Another major drawback of Node.js is its inability to perform high computation tasks.

Here are the common challenges faced by Node.js:

• Security issues

• Node.js, any program can be written to the file system while installing untrusted package files from npm.

• Issues with the module system

• GYP to build a module that links to C library is a major issue, and compatibility of module system with browsers is under question.

• Async APIs

Node.js was written in C++ while Deno is written in Rust language. It runs on Google V8 and supports Typescript. As Typescript is a superset of JavaScript, it is a runtime for JavaScript too.

WHAT IS DENO?

Deno is the Google runtime engine for JavaScript, which is secure and built on Google V8. It is a cross-platform for writing network applications using JavaScript and TypeScript. Ryan Dahl is the creator of both Deno and Node.js. He developed Deno to fix the mistakes and issues of Node.js and guarantees a secure environment for modern development.

Deno was developed with:

• Rust language: Node.js was written in C++ and Deno is written in Rust language.

• V8: It is Google's JavaScript runtime used in Chrome and Node.

• Tokio: a runtime written in rust language for writing applications

• TypeScript: Deno supports both JavaScript and TypeScript. This prevents unnecessary bloats.

Deno vs Node.js

Even though the purposes of both platforms are the same, they use different mechanisms. ES Modules is used by Deno as the default module system, while that of Node.js is CommonJS. Runtime has no access to the network, file system or environment in Deno. Access is granted explicitly guaranteeing better security. As Deno supports TypeScript out of the box, there is no need to installing and configuring tools to write TypeScript code. There are built-in tools like a test runner, code formatter and bundler in Deno.

nodejs

There are a few advantages to using Deno. It is possible to host modules everywhere by importing code via URL. Deno eliminates the use of the package manager. There is no need for a centralized registry for distributing Deno packages. Since all modules are downloaded, compiled and cached on the application run, there isn't any need for a dependency list.

Deno is similar to browsers and uses URLs for loading dependencies. It aims for better compatibility and provides a wide range of Web API. It designs API to promote TypeScript features. Deno minimizes core API size and provides a large standard library. It uses message passing channels. Deno could be used to perform computations and to create web servers.

Currently, there are over 150 contributors to Deno. Deno is a more secure and open source project that is a better alternative to Node.js.

TOP FEATURES OF DENO

• Security

Deno focuses on security than Node.js. It executes the code in sandbox denoting that runtime will not have access to the file system, network or other scripts. Users should explicitly allow the code to access these resources during runtime either by using flags or by responding positively. Deno does not allow the performance of delicate actions unless specific flags are passed, and run in a 'non-privilege' mode in default. The communications that are conducted within Deno are by message passing (Rust Language), allowing only a single auditable point for communications. Deno always dies on uncaught errors, unlike Node.js which adds to the security offered by Deno.

• Modules

Deno is similar to browsers as it loads modules using URLs. Deno packages can be distributed without the aid of a centralized registry or third-party module such as npm as it uses URLs. Creators can host their code wherever they are fit on the internet as the codes are imported using URLs. Deno downloads and caches all the imported modules. Unless the modules are asked for reloading, Deno will not download those modules. Since Deno caches all downloaded modules, developers can access the downloaded modules even when their website crashes or when they do not have internet access. Deno does not have external dependencies and has a centralized collection of standard modules that are reviewed by the core team. Deno is written with proper V8, rust, and tokio and has implemented Deno standard library in TypeScript. Deno is a safe environment to use, to build small scripting project in TypeScript.

• Browser compatibility

Deno has in-built tools that aim to be compatible with browsers. The in-built tools will transpile codes, enabling them to run even in older versions of browsers that do not support new versions of the language, preventing unnecessary bloats.

• TypeScript support

TypeScript is supported by Deno in default without any config files. It is also possible to write and execute programs in JavaScript with Deno. TypeScript can be compiled to JavaScript Babel and TypeScript compiler with ease. It adds optional types to JavaScript and supports large scale Java applications. TypeScript is the overhead of compilation since it is the main language.

• The standard library

Deno has a standard library that is easy to handle and import.

TO CONCLUDE

Deno is the new runtime in Google V8 that supports JavaScript and TypeScript. It is growing steadily within a short time from its release. As it serves decentralized modules, Deno is a necessary step in freeing the JavaScript from centralized package registry such as npm. Binaries of Deno are in development to avoid potential conflicts in the future. The creator of Deno and Node.js, Dahl expects the release of Deno version 1.0 in near real-time.