Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the top five reasons why Javascript developers prefer Deno

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail the five reasons why Javascript developers prefer Deno. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

To address many of the shortcomings of Node, NodeJS developer Ryan Dahl has released a new runtime.

People's initial reaction may be: "Great, another Javascript framework? just what I need." The author has also had the same reaction. After understanding its advantages, the author understands more clearly why Deno is exactly what Javascript developers at the back end of the year need.

Compared to Node, take a look at five reasons why JavaScript developers have a smoother and more modern experience with Deno.

1.Modern Javascript-ES module

If you are also a React developer, you should have noticed that the syntax for importing packages is different when using NodeJS. This is because Node was developed in 2009, and since then, many updates and improvements have been made to Javascript.

In React (and Deno), the modern import package from 'package' statement is used, while in Node, the const package = require ("package") statement is used.

The advantages of ES module import come from two aspects:

With import, you can selectively load only the desired fragments from the package, saving memory.

Loading is synchronized with require, while import loads modules asynchronously, which improves performance.

two。 Top-level await-use await outside of asynchronous functions

In Node, the await keyword can only be accessed in asynchronous functions. But in Deno, no matter where and what object you face, you can use await without having to package it as an asynchronous function.

Almost all Javascript applications contain many asynchronous functions. This upgrade makes the code cleaner and simpler.

3. Distributed package

Image source: unsplash

With Deno, you don't have to rely on NPM. We no longer need package.json, and every package is loaded from URL.

In NodeJS, to use packages, you must first install from NPM:

Npm i moment

Wait for installation, and then include it in the application:

Const moment = require ("moment")

In addition, whenever someone wants to run the NodeJS library locally, they have to install all dependencies from NPM. In Deno, packages are imported from URL, so if you want to use moment, just import the URL:

Https://deno.land/x/moment/moment.ts.

In terms of packages, another big advantage of Deno is that each package is cached on the hard disk after installation, which means that a package installation only happens once. If you want to import the dependency again anywhere, you do not need to download it again.

4. TypeScript works locally and does not require configuration.

Getting TypeScript to work with NodeJS requires multiple steps. Readers must install typescript, upgrade package.json and tsconfig.json, and make sure the module supports @ types.

In Deno, all you need to do is save the file suffix as .ts instead of .js, and the TypeScript compiler is built in.

5. Visit the browser API (Window, Fetch)

To make a HTTP request in Javascript, you can use Fetch API. In NodeJS, you do not have access to the browser API, so you cannot call the fetch function locally. You must first install the package:

Npm i node-fetch

Then import the package:

Const fetch = require ("node-fetch")

This is the only way to call the fetch function.

The local Deno has access to the object, which means that the reader can call fetch ("https://something.com"), as well as anything in the browser API) without installing any libraries. When combined with the advantages of top-level await, you can see how much simpler the Deno code is than the Node code:

The way Javascript code is written in 2020

Not only that, Deno has many other advantages, such as being more secure by default, being able to execute Wasm binaries, having many built-in libraries, and so on.

Image source: unsplash

The main points mentioned in this article are all interrelated and together make up a more modern 2020 back-end JavaScript runtime. As a React developer, the author prefers Deno.

Now I can use the import statement, I can use await anywhere, I can use TypeScript without any configuration, and I can even call fetch without installing the package. Everything is simple.

Another question is, will Deno eventually replace Node? Maybe, but it could take years. The NodeJS ecosystem is huge, and it takes time for Deno to catch up.

This is the end of the five reasons why Javascript developers prefer Deno. I hope the above content can be of some help and learn more. If you think the article is good, you can share it for more people to see.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report