Background story

Deno has been talking a lot lately, and it’s been said that “Deno could be the next big thing on the front end”, so keep an eye out.

Both Node.js and Deno are originated by Ryan Dahl

He started working on Node in 2009, but left the project a few years later. Back in 2018, he published 10 things I regret about Node.js, and he announced the creation of a new Deno project.

The author making github.com/ry

Ryan DahI mentioned the ten design errors of Node, many of which are basic design errors. Professional knowledge is required for in-depth understanding. I as small white, just sort out the list.

Regret not sticking with PromiseThe result is that nodes are full of different async API designs with async/await and promise that are extremely difficult to integrate until now.

Regret not switching from GYP to GN

Regret continuing to use GYP and not providing FFI

Regret can require (” somemodule “) anywhere

Regret that package.json provides the wrong “module” concept

Regret not paying attention to Security

Regret designing the software black hole node_modules

Sometimes NPM install takes a long time to install and then finds that the application has downloaded hundreds of MB of node_module.

Attach a speech video address: www.bilibili.com/video/BV1fp…

Deno

Deno is a new platform for writing applications in JavaScript and TypeScript. Both platforms share the same philosophy – event-driven architecture and asynchronous non-blocking tools to build Web servers and services.

How is Node different from Deno?

The two platforms serve the same purpose, but use different mechanisms. Deno uses the ES module as the default module system, while Node.js uses CommonJS. External dependencies are loaded using urls, similar to a browser. There is also no package manager and centralized registry, and modules can be hosted anywhere on the Internet. In contrast to Node.js, Deno executes code in a sandbox, which means that the runtime does not have access to the network, file system, or environment. Access needs to be explicitly granted, which means better security. Deno supports TypeScript right out of the box, which means we don’t need to manually install and configure tools to write TypeScript code. Another difference is that Deno provides a set of built-in tools, such as test runners, code formatters, and bundlers.

Deno does not require NPM package management

# Deno
import { serve } from "https://deno.land/[email protected]/http/server.ts";

# Node 
const server requrie('server')
Copy the code

Deno imports code through urls and can host modules anywhere on the Internet. Deno packages can be distributed without a centralized registry. There is also no need for package.json files and dependency lists, because all modules are downloaded, compiled, and cached while the application is running.

Will Deno really replace Node?

Krzysztof Piechowicz: Deno’s goal is not to replace Node.js, but to provide an alternative. Some of these differences are so controversial that it is hard to predict whether they will be formatted in the right way. I recommend that all Node.js programmers take note of this project. I’m not sure if the project will be a success, but it’s a great opportunity to see how Node.js can be implemented differently.

Speech video address: www.bilibili.com/video/BV1hi…

Give it a try

The appendix resources

Liverpoolfc.tv: deno. Land

Source: github.com/denoland/de…

# installation
curl -fsSL https://deno.land/x/install/install.sh | sh

# to run the Demo
deno run https://deno.land/std/examples/welcome.ts
Copy the code

example

import { serve } from "https://deno.land/[email protected]/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
  req.respond({ body: "Hello World\n" });
}
Copy the code

conclusion

We will see if Deno will be transformative!!