DeNO’s research skills: (1) Hello, from diversified installation to simple combat

Time:2021-6-4

The “DeNO research” series is launched on the official launch date of DeNO V1, and is updated on GitHub from time to time every week(https://github.com/hylerrix/deno-tutorial)。 Let’s learn DeNO step by step, first easy and then difficult, and develop our own DeNO web app for the future. Welcome to subscribe and exchange.

DeNO's research skills: (1) Hello, from diversified installation to simple combat

N + reasons for learning DeNO

After two years of DeNO open source, the official version of DeNO V1 is officially launched today. Maybe you’ve heard the name of DeNO, maybe you’ve used node.js, the last star project of DeNO author in a large number of projects, or maybe you’ve just come into contact with all this today… In a word, getting on the bus now is behind the accumulation of years of web app development experience in the industry, and in front of you is a blue ocean full of unknown and surprise.

A brief introduction to DeNO?

DeNO is a secure platform based on chrome V8 engine   When JavaScript and typescript run, the bottom layer is written by rust language (originally go), and the initiator is Ryan Dahl. Ry is also the initiator of node.js. When ry delivered node to the community for a period of time, looking back at the status quo of node, he put forward many defects that can not be ignored, so he brought a new project, DeNO.

It is the appearance of node.js around 2011 that brings JavaScript into the field of server application development; It also promoted the rapid development of Web front-end engineering through the leading modular idea at that time. At the same time verify and promote the   The development of Atwood’s law – any application that can be written in JavaScript will eventually be written in JavaScript.

Even though the major infrastructures (open source libraries, frameworks, scaffolding, etc.) built on node.js support the development of tens of thousands of core businesses from start-ups to major mainstream Internet companies, the new DeNO still has many forward-looking ideas under the historical burden of node itself, such as:

  • The bottom layer is developed with rust language: there are many excellent features of rust;
  • Native support for compiling typescript language: no additional manual configuration is required;
  • Core standard library maintenance in DeNO itself: there is no need to worry about how to select the third-party library, and there is no need to worry about the unprotected maintenance of these libraries;
  • Unique security sandbox support: by default, the script does not have read-write permission and needs authorization;
  • Support web standards as much as possible: no more manual configuration, most of the functions are out of the box;
  • Support es module standard: no longer need to bear the common JS “historical burden” of node.js;
  • Redesigned package manager: abandon the heavy node modules, and even easily import modules from URL;
  • Rethinking package.json: let the gradually huge package.json get a reasonable “release”;
  • Native support for JSDoc: and use it in the built-in document system;
  • Better tool chain support: developers really don’t want to be busy with various configuration processes any more;
  • Built in monitoring file function: make hot update more convenient and simple.

This is DeNO, an exciting project. More specific knowledge points will be gradually developed in the later part of this series.

The screenshot of the DeNO knowledge system diagram below is from the information extraction and retrieval system based on machine learningMagi.com“It can extract knowledge from natural language texts in any field into structured data, continuously aggregate and correct errors through lifelong learning, and then provide analytic, retrievable and traceable knowledge system for human users and other artificial intelligence.”. The contents in the figure are for reference only.

DeNO's research skills: (1) Hello, from diversified installation to simple combat

Excellent ecology, star exceeds 50K+

stayStar history websiteIn the past two years, we can see that the community’s attention to DeNO has steadily increased. It has been close to 20K + since it was released more than a month ago, and now it has reached the number of 50K + stars, which means that DeNO has been ranked in at least the top 70 in the global ranking of GitHub projects.

Up to now, the number of DeNO contributors born in two years has reached 270 + with 3K + commit, 416 / 1920 issues resolution ratio and 42 / 3273 PR resolution ratio (2020-05-12). At the same time, node has 2690 + contributors, 30K + commit, 977 / 11585 issues and 316 / 21192 pr.

The following figure shows the current star history trend of DeNO.

DeNO's research skills: (1) Hello, from diversified installation to simple combat

Bet on DeNO?

Everyone has their own reasons for learning DeNO. There is an interesting voice in the community: learning DeNO is a kind of “bet”, hoping that learning DeNO can completely give up node and get better programming opportunities in the future.

In fact, DeNO is still in its early stage, and the success of node.js has its own background and can not be copied. So it’s too early to bet all your learning on DeNO.

So what about DeNO? DeNO was born in the environment of “gift culture” of open source community. Together, we regard DeNO as a new life to join the big family, learn from each other’s strong points in the process of the whole web field, and jointly build DeNO, which is the best way to treat this “gift” at this stage.

You know, from node to DeNO, there are too many positive contributions from Chinese developers.

just for fun

Launched in the name of ECMA members and led by Alibaba, Tencent, etc《Node.js developer 2020 Annual Report》The younger the students are, the more attention they pay to DeNO. Therefore, this article focuses on a young Chinese Intern of Google, one of DeNO’s core contributors  @ Why learn DeNO?

To be fair, the main purpose of my initial participation was to think that “I have been using node, but I don’t understand its real working principle”. So when I first saw DeNO, I thought that “a better way to understand the principle of node is to make a new node by myself”.
——@kevinkassimo

DeNO's research skills: (1) Hello, from diversified installation to simple combat

This is my important attitude towards DeNO. When the university first entered the campus, it was the hottest time for node.js. I chose the big front-end field because of my love for node.js. In the next few years, I also participated in and held many front-end related activities. However, my understanding of node.js has not been better broken through because of my identity limitations.

In the year of graduation, node.js has developed a huge ecosystem. We can find a large number of NPM libraries to solve our own programming needs. This also shows that we are getting more and more familiar with node.js. Now DeNO is brand new. In order to better understand DeNO, including node.js, and keep up with the development process of the whole web, I also started my journey of DeNO.

At the same time, a bigger mindset, like the Autobiography of Linus Torvalds, the father of Linux, “just for fun.”. In addition to all kinds of front-end business that they are responsible for in the workplace, out of the fun mentality, out of the taste mentality, out of a kind of “uncared” mentality, they have opened all this.

So: why do you learn DeNO?

Various installation methods of DeNO on MacOS

In the developer community, in addition to the most common windows operating system, Linux and MacOS environment also account for a significant proportion. There are relevant solutions for the installation of DeNO on various platforms. This section, including all subsequent chapters, will learn DeNO on MacOS by default. In the future, it may involve the deployment of DeNO web app on Linux cloud server.

Therefore, if your operating system is MacOS, it is very convenient to learn from this article. If your local environment is Linux or windows, except for some different package managers, different installation directories, and different configuration methods of environment variables, it will not stop you from learning DeNO deeply. According to their own operating system, we can search and discuss other installation methods of DeNO in DeNO official, DeNO community or issues area of DeNO Research Series warehouse.

What do you need to pay attention to when installing a package from the command line? Of course, it is whether the software package is successfully installed, what logs are in the installation process, whether it can run successfully, and whether it can be upgraded and uninstalled by simple configuration… Based on this point of view, the following installation method will select DeNO – V to verify whether the installation is successful (generated an idea: “command to install software Checklist”, interesting).

This section focuses on the installation process. More in-depth installation principles will be involved in the future. Let’s start!

Installation method 1: install directly with curl

DeNO's research skills: (1) Hello, from diversified installation to simple combat

Curl is used to transfer data on the command line or in scripts. Here, the first installation method is to download the deno.zip package in the remote installation script install.sh through curl and execute it immediately, as follows.

$ curl -fsSL https://deno.land/x/install/install.sh | sh
# ######################################################################## 100.0%-#O#- #   #                                                                 ######################################################################## 100.0%
# Archive:  /Users/${USER_NAME}/.deno/bin/deno.zip
#   inflating: deno
# Deno was installed successfully to /Users/${USER_NAME}/.deno/bin/deno
# Manually add the directory to your $HOME/.bash_profile (or similar)
#   export DENO_INSTALL="/Users/${USER_NAME}/.deno"
#   export PATH="$DENO_INSTALL/bin:$PATH"
# Run '/Users/${USER_NAME}/.deno/bin/deno --help' to get started
$ deno -V
# zsh: command not found: deno

At this point, the installation is half done. From the terminal log after successful installation, it can be seen that DeNO has been successfully installed in ~ /. DeNO of the user. After entering this directory, it can be seen that only the binary software ~ /. DeNO / bin / DeNO is left, and the deno.zip before decompression has been deleted. Next, entering DeNO – V does not run the DeNO command successfully. We need to manually configure the environment variables to let the terminal know where to execute the DeNO command.

Note: ${user}_ Name} is your user name under your own operating system. You need to change it to your own user name manually.

According to the log prompt, after executing the following command, enter DeNO – V to see that the DeNO command has been successfully configured.

$ export DENO_INSTALL="/Users/${USER_NAME}/.deno"
$ export PATH="$DENO_INSTALL/bin:$PATH"
$ deno -V
# deno 1.0.0-rc2
$ which deno
# /Users/${USER_NAME}/.deno/bin/deno
$ echo $PATH
# /Users/${USER_NAME}/.deno/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/...

The version of DeNO installed here is 1.0.0-rc2. As of May 13, 2020, the latest version is   1.0.0-rc3, the command to let DeNO self update is as follows.

$ deno upgrade
# Checking for latest version
# Version has been found
# Deno is upgrading to version 1.0.0-rc3
# downloading https://github.com/denoland/deno/releases/download/v1.0.0-rc3/deno-x86_64-apple-darwin.zip
# downloading https://github-production-release-asset-2e65be.s3.amazonaws.com/133442384/...

Installation mode 2: install from homebrew

DeNO's research skills: (1) Hello, from diversified installation to simple combat

If you have successfully installed DeNO through curl just now, and now you want to try homebrew installation, you can manually uninstall DeNO according to the known DeNO directory and environment variable values, and make sure that the relevant directory (~ /. DeNO) and environment variable (export – P | grep DeNO for acceptance) are cleared.

#Install homebrew
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Now let’s use homebrew, one of the most famous package managers on MacOS, to install DeNO. Since homebrew automatically checks for updates every time it is executed by default, the display is extremely slow   Updating homebrew… Does not show the specific progress. You need to temporarily close homebrew and automatically update it before formally installing DeNO.

$ export HOMEBREW_NO_AUTO_UPDATE=true
$ brew install deno
# ==> Downloading https://homebrew.bintray.com/bottles/deno-0.42.0.catalina.bottle.tar.gz
# ==> Downloading from https://akamai.bintray.com/b4/b4f91dd079eee18b85b157bb03b1535935a37d9fb6f078e271a7b48b2afd34ea?__gda__=exp=15
# ######################################################################## 100.0%
# ==> Pouring deno-0.42.0.catalina.bottle.tar.gz
# ==> Caveats
# Bash completion has been installed to:
#   /usr/local/etc/bash_completion.d

# zsh completions have been installed to:
#   /usr/local/share/zsh/site-functions
# ==> Summary
# ?  /usr/local/Cellar/deno/0.42.0: 9 files, 41.4MB
# ==> `brew cleanup` has not been run in 30 days, running now...
# Error: Permission denied @ apply2files - /usr/local/lib/node_modules/expo-cli/node_modules/.bin/detect-libc

From the above terminal log and  https://formulae.brew.sh/formula/deno  As you can see, the latest version of DeNO on homebrew does not support deno-v1.0.0-rcx, only supports 0.42.0. And homebrew will place the DeNO software in the  / The environment variables are automatically updated in / usr / local / cell / DeNO.

$ deno -V
# deno 0.42.0
$ which deno
# /usr/local/bin/deno
$ ll /usr/local/bin/deno
# lrwxr-xr-x  1 ${USER_NAME}  admin    30B May 13 10:53
# /usr/local/bin/deno -> ../Cellar/deno/0.42.0/bin/deno

Installation mode 3: installation from asdf

DeNO's research skills: (1) Hello, from diversified installation to simple combat

Asdf is an extensible version manager. It supports ruby, node.js, elixir and Erlang. We can install DeNO through asdf, including managing multiple versions of DeNO quickly. First, install asdf. You can use git to install and manually configure environment variables. You can also install asdf through homebrew.

$ brew install asdf
# ==> Downloading https://github.com/asdf-vm/asdf/archive/v0.7.8.tar.gz
# Already downloaded: /Users/${USER_NAME}/Library/Caches/Homebrew/downloads/34d73b51ece171e6c4ffe51147d4599c5b7f78749b379dec98ab7dd9174bd595--asdf-0.7.8.tar.gz
# ==> Caveats
# Bash completion has been installed to:
#   /usr/local/etc/bash_completion.d
# 
# zsh completions have been installed to:
#   /usr/local/share/zsh/site-functions
# ==> Summary
# ?  /usr/local/Cellar/asdf/0.7.8: 104 files, 219.6KB, built in 18 seconds

The above needs to configure the asdf address of DeNO before installing DeNO. Asdf can easily control the multi version of DeNO.

$ asdf plugin-add deno https://github.com/asdf-community/asdf-deno.git
$ asdf plugin list --urls
# deno  https://github.com/asdf-community/asdf-deno.git
$ asdf install deno 1.0.0-rc3
# /Users/${USER_NAME}/.asdf/plugins/deno/bin/install: line 27: [: 100-rc3: integer expression expected
# ∗ Downloading and installing deno...
# Archive:  /Users/${USER_NAME}/.asdf/installs/deno/1.0.0-rc3/bin/deno.zip
#   inflating: /Users/${USER_NAME}/.asdf/installs/deno/1.0.0-rc3/bin/deno
# The installation was successful!
$ which deno
deno not found

It can be seen that DeNO has been successfully installed through asdf, but a soft link needs to be created, that is, to bind environment variables.

#Create soft link
$ ln -s /Users/${USER_NAME}/.asdf/installs/deno/1.0.0-rc3/bin/deno /usr/local/bin
$ deno -V
# deno 1.0.0-rc3
$ which deno
# /usr/local/bin/deno
$ ll /usr/local/bin/deno
# lrwxr-xr-x  1 ${USER_NAME}  admin    50B May 11 18:37
# /usr/local/bin/deno -> /Users/${USER_NAME}/.asdf/installs/deno/1.0.0-rc3/bin/deno
#Global configuration DeNO version
$ asdf global deno 1.0.0-rc3
#Set the DeNO version in the current directory
$ asdf local deno 1.0.0-rc3
#See all the versions of DeNO that can be installed
$ asdf list all deno
#View the current DeNO version
$ asdf current deno # 1.0.0-rc3 (set by /Users/${USER_NAME}/.tool-versions)

Installation mode 4: install from the source code

Due to the limited space, a lot of knowledge can be extended from the source code installation, this article does not cover, and will be updated in the future.

What kind of installation mode should I choose?

DeNO's research skills: (1) Hello, from diversified installation to simple combat

Based on the operating system you want to use and the way you want to learn DeNO, you can decide different installation methods from the perspectives of “command line quick installation”, “package manager single version installation”, “package manager multi version installation and control”, “source code installation”.

DeNO’s simple combat

Prepare one   Hello World   program

Brian Kernighan wrote a programming book called C programming language in 1978, in which the Hello world program was quoted for the first time, and this tradition has been handed down to the present. Here, the first program about DeNO can also start with Hello world.

DeNO's research skills: (1) Hello, from diversified installation to simple combat

Because DeNO has built-in typescript runtime, the example here is welcome.ts provided by the official website, as follows.

// welcome.ts
//Import the server.ts module from the URL, and extract (ES6 deconstruction assignment) the serve object
import { serve } from "https://deno.land/std/http/server.ts";
//Instantiate a serve object
const s = serve({ port: 8000 });
//Print the port address monitored by the program on the terminal
console.log("http://localhost:8000/");
//Using the new es9 feature for await syntax, when accessing the listening port, it returns a "Hello world"
for await (const req of s) {
  req.respond({ body: "Hello World\n" });
}

If the above welcome.ts can run successfully in DeNO, what does that mean? In just a few lines of code, we can see that DeNO itself provides official standard library (solves the cost of finding a third-party library for comparative learning), DeNO’s modules can be imported directly from the URL (a unique way of import), DeNO supports the latest es standard (no need to be busy configuring various ES6 + language transferers), DeNO has a built-in typescript runtime (no need to manually install and configure the typescript transporter).

Hello World

Now let’s execute welcome.ts, because the remote server.ts is introduced into the code, and other files are introduced into the server.ts, DeNO will now uniformly download to the global directory and execute the files.

$ deno-tutorial git:(master) deno run --allow-net demos/welcome.ts
# Compile file:///Users/${USER_NAME}/WorkSpace/Hylerrix/deno-tutorial/demos/welcome.ts
# Download https://deno.land/[email protected]/http/server.ts
# Download https://deno.land/[email protected]/encoding/utf8.ts
# Download https://deno.land/[email protected]/io/bufio.ts
# Download https://deno.land/[email protected]/testing/asserts.ts
# Download https://deno.land/[email protected]/async/mod.ts
# Download https://deno.land/[email protected]/http/_io.ts
# Download https://deno.land/[email protected]/io/util.ts
# Download https://deno.land/[email protected]/path/mod.ts
# Download https://deno.land/[email protected]/path/win32.ts
# Download https://deno.land/[email protected]/path/posix.ts
# Download https://deno.land/[email protected]/path/common.ts
# Download https://deno.land/[email protected]/path/separator.ts
# Download https://deno.land/[email protected]/path/interface.ts
# Download https://deno.land/[email protected]/path/glob.ts
# Download https://deno.land/[email protected]/path/_constants.ts
# Download https://deno.land/[email protected]/path/_util.ts
# Download https://deno.land/[email protected]/fmt/colors.ts
# Download https://deno.land/[email protected]/testing/diff.ts
# Download https://deno.land/[email protected]/path/_globrex.ts
# Download https://deno.land/[email protected]/async/deferred.ts
# Download https://deno.land/[email protected]/async/delay.ts
# Download https://deno.land/[email protected]/async/mux_async_iterator.ts
# Download https://deno.land/[email protected]/textproto/mod.ts
# Download https://deno.land/[email protected]/http/http_status.ts
# Download https://deno.land/[email protected]/bytes/mod.ts

This opens localhost:8000 The prompt is successful.

DeNO's research skills: (1) Hello, from diversified installation to simple combat

More of DeNO’s actual combat

The future is constantly updated inOpen source e-book warehouse of DeNO researchIn the middle.

reference material

Subscription & to be continued

This article belongs toDeNO Research SeriesIn the future, we plan to gradually expand the added chapters and fill in more articles, such as:

  • Basic part: Learn DeNO’s basic knowledge step by step;
  • Node: first easy, then difficult, supplement node knowledge, explore the differences and similarities with DeNO;
  • Rust: explore more knowledge about rust at the bottom of DeNO;
  • Front end: explore the way of DeNO web front-end application development;
  • Back end: explore the way of DeNO web back end application development;
  • Architecture: go to the bottom of DeNO to read V8 and learn architecture.

Welcome to subscribe and grow together. Welcome to star, watch & issue open source warehouseDeNO’s art of study! Three in a row.