Deno is coming, is Node going to be cold?

Posted May 27, 20203 min read

background story

Recently, the discussion of Deno is quite popular, and it is said that "Deno is likely to be the next big event of the front end", so pay attention.

The authors of Node.js and Deno are Ryan Dahl

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

Author GitHub https://github.com/ry

Ten design errors of Node mentioned by Ryan DahI, many of them are design errors at the grassroots level, and in-depth understanding requires professional skills. As Xiaobai, I just sorted it out.

Regret The result of not insisting on using Promise is that Node is full of different async API designs filled with async/await and promises, which are extremely difficult to integrate until now.

addPromise

removePromise

Regret not transferred from GYP reinforcement system to GN

Regret Continue to use GYP, no FFI provided

Regret You can also require("somemodule") anywhere

Regret package.json provides the wrong "module" concept

Regret Not paying attention to security(Security)

Regret designed the black hole in the software world node \ _modules

Sometimes npm install has to wait a long time, and then found that the application downloaded hundreds of mb of node \ _module.

Attach the address of the speech video: https://www.bilibili.com/vide...

Deno

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

What is the difference between Node and Deno?

The two platforms have the same purpose, but use different mechanisms. Deno uses ES modules as the default module system, while Node.js uses CommonJS. External dependencies are loaded using URLs, similar to browsers. There is no package manager and centralized registry, you can host modules anywhere on the Internet. In contrast to Node.js, Deno executes code in the sandbox, which means that the network, file system, and environment cannot be accessed at runtime. Access permissions need to be explicitly granted, which means better security. Deno supports TypeScript 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/std@0.53.0/http/server.ts";

# Node
const server requrie('server')

Deno imports code via URL and can host modules anywhere on the Internet. The Deno software package can be distributed without a centralized registry. There is no need for a package.json file and a list of dependencies, because all modules are downloaded, compiled, and cached while the application is running.

Deno will really replace node?

Krzysztof Piechowicz:The goal of Deno is not to replace Node.js, but to provide alternative solutions. Some of these differences are quite controversial, and it is difficult to predict whether they will be formatted in the correct way. I suggest that all Node.js programmers pay attention to this project. I am not sure whether the project will succeed, but this is a great opportunity to observe how Node.js is implemented in different ways.

Speech video address: https://www.bilibili.com/vide ...

try it

Appendix Resources

Official website: https://deno.land

Source code: https://github.com/denoland/deno

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

# Run Demo
deno run https://deno.land/std/examples/welcome.ts

example

import {serve} from "https://deno.land/std@0.53.0/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"});
}

to sum up

Whether Deno will bring change, we will wait and see! !