In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is to share with you about the five reasons why Javascript developers prefer Deno rather than Node. I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
Ryan Dahl, author of NodeJS, has released a new runtime designed to address many of Node's shortcomings. Your initial reaction may be "Oh, great, another Javascript framework? just what I need." Don't worry, I have the same reaction. After understanding the advantages, I also saw why Deno is exactly what back-end Javascript developers need in 2020. Let's take a look at five reasons why javascript developers use Deno vs. Node to get a smoother, more modern experience.
1. Modern Javascript--ES Modules
If you are a React developer like me, you will notice that the syntax for importing packages using NodeJS is different. This is because Node came out in 2009, and a lot of updates and improvements have been made to Javascript since then.
In React (and Deno), we use import package from 'package' syntax to import packages, while in Node, we use const package = require ("package") syntax.
The advantages of ES Modules import are for two reasons:
Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community
With import, you can selectively load only the parts you need from the package, which saves memory.
Loading is synchronized with require, while import loads modules asynchronously, improving performance.
If you notice in the figure above, we are importing the moment package from URL, which will give us the next advantage of Deno.
two。 Decentralized package
With Deno, you are no longer dependent on NPM. Yes, package.json is no longer needed, and every package is loaded from URL.
In NodeJS, to use a package, you must first install it from NPM:
Npm i moment
Wait for it to install, and then include it in your application:
Const moment = require ("moment")
In addition, any time someone wants to run your NodeJS repository locally, you must install all dependencies from NPM.
In Deno, the package is imported from URL, so if you want to use moment, just import https://deno.land/x/moment/moment.ts.
Another big advantage about software packages in Deno is that each package is cached on the hard drive after installation. This means that the installation of the package occurs only once, and if you want to import the dependency again anywhere, you do not have to download it.
3.TypeScript is native and does not require configuration
Getting TypeScript to work with NodeJS is a multi-step process. You must install TypeScript, update package.json,tsconfig.json, and make sure your module supports @ types.
In Deno, all you have to do is save the file as .ts instead of .js, and the TypeScript compiler has been installed.
4. Top-level await-- uses await functionality in addition to asynchronous functions
In Node, the await keyword can only be accessed in asynchronous functions.
With Deno, you can await anything anytime, anywhere without having to wrap it in an asynchronous function.
Almost all Javascript applications contain many asynchronous functions, and this upgrade makes the code cleaner and simpler.
5. Visit the browser API (Window,Fetch)
To make a HTTP request using javascript, we can use Fetch API. In NodeJS, we don't have access to Browser API, so we can't call the get function directly. We must first install the package:
Npm i node-fetch
Then import the package:
Const fetch = require ("node-fetch")
Only in this way can we make the call.
Deno natively has access to window objects, which means you can continue to call fetch ("https://something.com")" and any other objects in Browser API without installing any libraries.
Combined with the advantages of top-level await, you can now see that Deno code is much simpler than Node code:
The way Javascript code is written after 2020
It's not over.
Deno has many other advantages, such as being safer by default, being able to execute Wasm binaries, having many built-in libraries, and the list continues.
All the points mentioned in this article are interrelated to form a more modern 2020 back-end javascript runtime. As a React developer, I resonate with Deno. Now, I can use the import syntax, write await wherever I need it, use TypeScript without any configuration, and even call fetch without installing the package. It's simple.
Will Deno eventually replace Node? Maybe. This could take years. The NodeJS ecosystem is so large that it may take some time for Deno to catch up. But Javascript developers have been fond of Deno's new project recently, so if you plan to start a new project as soon as possible, it's definitely worth studying.
These are the top 5 reasons why Javascript developers prefer Deno to Node, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.