Deno v1 released recently and is creating a buzz. Several proclaim Deno to bring about the end of Node.js. However, at this moment, it sounds like an exaggeration or an over-emphatic statement. The comparisons are bound to happen. After all, the creator of both Deno vs Node.js happen to be the same person, Ryan Dahl.
What happens when the founder of Node.js, Ryan Dahl in his talk “10 Things I Regret About Node.js” mentions both runtime and package manager in a single executable instead of the package-management program. While Ryan released the inherent flaws in development, however, it was not possible to make changes in legacy code.
Voila, that’s when the idea of Deno was born to improve Node.js. If you want to understand the difference between or decide whether to opt for Node.js, partner with Node js application development company.
Advantages of Deno
- Well designed module system. Security is the focal point
- Supports TypeScript out of the box.
- Ships a single executable.
- Built-in dependency inspector and a code formatter.
Here is why Deno is creating news:
Node.js allows seamless access encompassing filesystem, outgoing requests, environment variables, and more. While it is indeed a privilege to avail such access, there is also a flipside. This unrestricted access opens up a world of risks during the development or coding process.
- Deno provides command-line flag ‘–allow-net’ to give access to all external permissions for the script.
- Deno uses command-line arguments to allow or disable access to different security features.
- Provides code to read from the folder, giving a security exception.
- Flags as part of the command line executes the script, providing permissions required for code.
Unless stated clearly and otherwise, Deno won’t be able to delete files from your program without your permission. Security is the focal point of Deno. It won’t be able to access the hard drive or execute any potentially malicious actions without permission.
Ever thought of rising above the clutter? Node.js provides npm to manage your packages. However, Deno lets you directly install packages from URL or directly use by importing packages as a library in the script from URL. This eliminates the ‘package.json‘ file for managing dependencies, as well as ‘node_modules‘ folder.
This is one of the biggest advantages of Deno. But how does Deno manage dependencies? It is simple by allowing you to require modules from anywhere.
There is no need to have your own centralized repository. This is one of the biggest differentiators; however, it is controversial also, since importing modules from 3rd party sources increases vulnerability.
Deno supports ES Modules.
In Node.js, you load CommonJS modules using the require keyword and they all, standard and third-party alike, implicitly come from npmjs.com. In Deno, you load ES modules using the import keyword and explicitly state the URL.
Deno modules can be hosted anywhere in absence of a centralized repository for third-party modules as well as cached and compiled locally, which means it is not updated unless asked for clearly.
This quintessentially means you can run Deno programs already on your laptop with all imports (needs to be resolved once).
Node.js design shortcomings
According to Dahl, the founder of Node.js and who designed both Node.js and Deno, Node.js comes with few design issues. Deno fixes all three problems. The core issues highlighted include:
- Poorly designed module system, with centralized distribution
- Several legacy APIs requiring support
- Lack of security
Main comparisons with NodeJS
- Deno’s core written in Rust programming language (core emphasis on safety) and Tokio. Nodejs was in C++.
- Typescript is good for large application.
- ES6 import statements a decentralized approach as dependency management.
- No npm, effectively meaning that it does not use any package manager like npm and does not have package.json for module handling.
- Deno will break on unhandled exceptions which is not the case in NodeJS.
- Deno needs explicit permissions for file, network, environment access.
Will Deno replace Node.js?
Maybe or maybe not. Node.js has a strong ecosystem and huge. On the other hand, Deno is in its nascent stage and will take time to catch up.
At this point, Deno is a cool new environment for building small private scripting projects in TypeScript. According to Dahl, Deno will never really challenge the success of Node.js considering the popularity. Nevertheless, once Deno matures it may become a viable choice for building larger projects.
Only time will tell whether Deno will pick up. At the moment or in the near future, Node.js is the way to go and if put in the words of Ryan, “Node is not going anywhere.”