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

Will Deno replace NodeJS?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "will Deno replace NodeJS". In daily operation, I believe many people have doubts about whether Deno will replace NodeJS. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "will Deno replace NodeJS?" Next, please follow the editor to study!

First, start from the beginning

In 2018, Ryan spoke in a speech about what he thought were 10 problems with Node. At the end of the speech, he showed that he was building a small system of Deno, known as Node.js 2.0, which was improved and more secure.

Two years later, Deno 1.0 was officially released. There is a whole new JavaScript runtime environment at the back end, but it is written in Rust, not C++. It is based on the Tokio platform, which provides JavaScript with the asynchronous running environment it needs, and can still run the Google V8 engine.

Second, is there anything new?

Not only are we talking about a new JavaScript runtime environment that is fully compatible with existing Node.js, Ryan also took advantage of this opportunity to add something to Deno that he thought was missing in his early creation.

1. Security integration

By default, Node.js allows users to access everything, which means you can read and write to the file system, make requests, access environment variables, and so on. While it is advantageous to have this access as a developer, it can also pose a security risk if you are not careful when writing your own code.

Therefore, Deno uses command-line parameters to enable or disable access to different security features. If you need to allow your script to access the / etc folder, type:

Deno-allow-read=/etcmyscript.ts

Your code will be read from the folder and you will get a security exception prompt. This is similar to the way other platforms handle security.

If you are an Android user, you must have received requests from many applications to allow them to access different systems (such as contacts, phones, folders, etc.) on your phone. It's the same here. By using these flags on the command line where the script is executed, you can provide the permissions required by the code.

two。 A more complete standard library

JavaScript has improved its standard library since the first version of Node, but it still has many shortcomings compared with other languages.

Deno also tries to improve this, and it is said that it will have a very complete standard library that allows developers to use official tools to perform basic tasks, and only external libraries (alaNPM) to accomplish complex tasks.

In essence, Deno works right out of the box, and its own tools can add colors to terminal text, manipulate external data structures (such as binary, csv, yaml, and other data structures), generate UUID, and even write websockets. There are other more basic modules available, such as file system access, date helper functions, http-related functions, and so on.

3. Integrated version of TypeScript

If you are a loyal user of TypeScript, Deno will do a lot of work for you without external tools, and the conversion of JavaScript can be done internally by default, which is nothing to worry about.

Although Deno does a lot of work by default, you can overwrite the configuration with your own tsconfig.json file:

Deno run-c tsconfig.json [your-script.ts]

The default mode is to use strict mode, so any careless coding operation will receive an immediate warning.

4. NPM and node_modules folders are no longer needed

This is a big problem. Is it too bloated? Is this way of decentralizing dependencies wrong? This is naturally one of the most controversial aspects of Node, and Deno decided to get rid of it completely.

So how does Deno handle dependencies? The current method is to allow you to obtain the module from anywhere. In other words, you can do this:

Import * as log from "https://deno.land/std/log/mod.ts";

You don't need to have your own centralized repository, but you have to be careful, because importing modules from third-party sources that you can't control will leave you in an open state.

In fact, our good friend package.json is also missing. Dependency management is now simplified by listing a series of modules and their respective URL in a file called deps.ts. You must ask, what about version control? You can specify the package version on URL. It's not very convenient, but it works.

A normal deps.ts file looks like this:

Export {assert} from "https://deno.land/std@v0.39.0/testing/asserts.ts"; export {green, bold} from" https://deno.land/std@v0.39.0/fmt/colors.ts";

This will re-export the module. If you want to change the version of the module, you need to simplify the URL accordingly. The first time the script is executed, the imported code is cached until it is run again with the-- reload flag.

5. Anything else?

Deno has other features, such as more out-of-the-box tools, including test runners, debuggers, file monitors, and so on. But then again, some of these are just language-provided API interfaces, and you need to write your own tools to use them.

Take the file monitor API interface provided by Deno.watchFs as an example. If you are looking for a solution similar to nodemon, you must do it yourself. Here is a 23-line script to solve a similar problem:

Will Deno replace Node.js soon?

To be honest, not necessarily. Some people have been using Node js since the launch of Node.js version 0.10, and even put it into production. We did this in the past because there was no similar system.

PHP, Python and even Ruby can't be compared with JavaScript and asynchronous Imax O models on the back end, let alone Java and. NET. Over the years, Node and JavaScript have been improving and upgrading to meet the needs of the industry.

Is it perfect? Of course not. Like everything else in life, it's hard to be perfect in programming languages.

Deno is no exception. At present, it is just an idea that plans to achieve the goal in two years. It has not been tested and tested in the production system, has not been reviewed, nor has it been applied to strange and unexpected uses, and we cannot understand how it deals with these extreme situations.

Maybe in a year's time, we will hear companies share their experience with using Deno, how they address newly discovered defects, and eventually, the group behind it will use Deno to make the most of it. Before that, the Deno was just a toy for early users.

Will it replace Node? Who knows? let's wait and see!

At this point, the study on "will Deno replace NodeJS" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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