Node.js and Deno both serve as runtimes for JavaScript and have a common producer, Ryan Dahl. As Node.js was introduced in 2009, many have become comfortable with its variety of functions due to the use of Javascript. But, there were a couple of features Ryan Dahl admitted that he should have focused more on, such as security, modules, dependencies.
In 2018 at the JSConf EU, Ryan Dahl talked about design flaws in Node. He regretted some of the choices that he made during its development. This was because of the limited features JavaScript language provided back in 2009.
All the algorithm flaws discussed could only be fixed by debugging the core code of Node, making it a lengthy and costly process. To prevent this, Ryan Dahl ended legal support of this runtime and introduced a new and improved, Deno. It’s an anagram of Node.
He confirmed that Deno wasn’t made to replace Node, so node developers don’t need to worry. They both serve as JavaScript runtimes, allowing access to JS outside of web browsers. Here are some comparison points between Node and Deno to help you gain a deeper understanding of the two.
In-Depth View Of Node And Deno
Node.js, an open-source server environment, was created from C++ language, and it leverages the V8 engine to run Javascript code. Originally, the V8 engine was made for Google Chrome to execute Javascript in the browser very quickly.
Similarly, Deno relies on the V8 engine. However, it was made by using a programming language called Rust, having a similar syntax as compared to C++. This language places special emphasis on security.
Node.js falls behind in terms of security. When a node app runs, it can easily open file systems or access networks. Deno prevents this by asking permission from the app user to execute a function. It can’t access the file systems or environmental variables without writing the command for allowance.
On Deno’s official website, an example is given of running a program that returned a network access error if network access wasn’t allowed. There are a variety of permission functions that range from reading to editing a file.
Design of APIs
Both Node and Deno keep their APIs open for web development, allowing professionals to make programs that can’t only read or write files but also deliver or receive requests for accessing networks.
At the time of production of Node, there was no built-in support for the use of Promises. Thus, Node’s API for asynchronous operations were designed to implement the error callback convention. Presently, Node does have access to Promises, and the async/await syntax, but it still requires the use of callbacks for backward compatibility.
Deno’s API takes advantage of the modern features in Javascript. All asynchronous operations return Promises. It also supports using top-level await in your main script. This eliminates the need for wrapping the main body of your code in an async function.
Browser Optimized
Deno’s development team has embedded browser APIs’ in required areas. It provides a global window object and APIs such as Web Worker and WebAssembly. These help to create web servers that function similar to client-side Javascript programs.
In simple terms, Deno applications written in Javascript that don’t use the global Deno namespace can run on modern browsers without modifications. The window object is unavailable in Node, but fetch can be used by accessing a third-party library.
Usage of Modules
Deno uses ES modules, the official custom packages that give access to Javascript code. Node.js used the CommonJS module because Javascript didn’t have its module at the time of Node’s invention.
Node installs and manages third party modules using its package manager called npm. It’s used for accessing npm’s online registry, where all the third-party packages are available.
When npm is used to install a package into your project, a package.json file is utilized, which allocates the name and suitable range of its versions. Any packages that the package installed depends on are stored in a node_modules folder, which is inside your project.
Deno loads modules by importing their URLs. These packages don’t require a centralized registry compared to npm, i.e., a package manager. NPM results in large node_modules folders, with the added difficulty of keeping them secure.
Deno enables package creators to present their code at suitable places. It eliminates the need for package.json and node_modules. When an application is started, Deno downloads all the imported libraries and stores them temporarily.
Deno creators ask users to check if they are stored in their version control systems or repositories. They can access that version of the modules when they were downloaded, even if the URLs stop working.
Access to Third-Party Modules
Node has a wide family of packages and libraries available. In June 2019, the total number of packages registered in the npm registry crossed 1 million and surpassed 1.3 million in 2020. Some may not be working currently, but it gives the advantage of accessing a large library for developers.
Deno eliminates the need to depend on a package manager. Instead, scripts can import modules from any public URLs. One can encounter difficulty in importing a package if they don’t know which is suitable. Fortunately, the Deno website provides a list of compatible open source modules. Currently, there are 1550 modules.
Deno also provides a standard library of functions for carrying out general operations. These modules are assessed by the Deno core team for providing high-quality code. Node can access them only via third party packages.
Wrapping Up
This article wasn’t written to support any of the two entities but to easily distinguish between them. Both of them offer one purpose but have different functionality. Deno displays a couple of advantages that include a sound approval system and exclusive typescript support. Its interface and designing tools provide a constructive environment and a great developer experience.
Whereas, Node has a great maturing ecosystem as it’s been more than a decade since its development. Currently, Node.js has a vast amount of documentation and tutorials available, making it a supportive application for creating web sites.
__________________________
About the Author: Nouman provides ghostwriting and copywriting services. His educational background in the technical field and business studies helps him in tackling topics ranging from career and business productivity to web development and digital marketing. He occasionally writes articles for Dynamologic Solutions.