The Deno Delve series will be released on the day of the official release of Deno V1, and will be updated weekly on Github (github.com/hylerrix/de…) . Let’s learn Deno step by step, first easy and then difficult to complement Node, for the future development of their own Deno Web App. Welcome to subscribe, welcome to communicate.

N+ reasons to learn Deno

Two years after Deno opened its source, the much-anticipated Deno V1 officially debuted today. Maybe you’ve already heard of Deno, maybe you’ve already used Deno’s last star project, Node.js, extensively in your projects, or maybe you’re just starting out today… In a word, now get on the bus, behind the industry is the accumulation of many years of Web App development experience, in front of a Deno blue sea full of unknowns and surprises.

Deno?

Deno is a secure JavaScript and TypeScript runtime based on the Chrome V8 engine, written in the Rust language (originally selected as Go) by Ryan Dahl. Ry is also the initiator of Node.js. After Ry delivered Node to the community for a period of time, he looked back at the status quo of Node and proposed many defects that could not be ignored, thus bringing a new project, Deno.

It was the emergence of Node.js around 2011 that officially brought JavaScript into the field of server-side application development. It also promoted the rapid development of Web front-end engineering through the leading modularity idea at that time. It also validated and promoted Atwood’s law, which states that any application that can be written in JavaScript will eventually be written in JavaScript.

Spring up, even if nowadays in the Node. Js built on major infrastructure (open source library, framework, scaffolding, etc.) to support the from startup to tens of thousands of leading Internet firms are core business development, but in the Node itself is not so easy to put aside, under the historical burden of newborn Deno still has a lot of forward-looking ideas, Such as:

  • The bottom layer is developed using Rust language: many of Rust’s good features are supported;
  • Native support for compiling TypeScript languages: no additional tedious manual configuration;
  • The core standard library is maintained in Deno itself: there is no need to worry about the selection of third-party libraries and the insecure maintenance of these libraries;
  • Unique security sandbox support: By default, scripts do not have read and write permissions and require authorization.
  • Support Web standards as much as possible: no more manual configuration, most features out of the box;
  • Support for ES module standards: No longer burdened with node.js CommonJS “baggage”;
  • Redesigned package manager: Ditching heavy Node Modules and even making it easy to import Modules from urls;
  • Rethinking package.json: Let the growing package.json get a reasonable “release”;
  • Native support for JSDoc: and use it for the built-in documentation system;
  • Better toolchain support: Developers really don’t want to be tied up in various configuration processes;
  • Built-in monitor file feature: Make hot updates easier and easier.

This is Deno, an exciting project. More detailed knowledge will be developed in the later part of this series.

Magi.com, a machine learning-based information extraction and retrieval system, “extracts knowledge from natural language text in any field into structured data that is continuously aggregated and corrected through lifelong learning, To provide human users and other AI with a body of knowledge that can be analyzed, retrieved, and traceable.” The contents in the figure are for reference only.

Excellent ecology, Star quantity broken 50K +

On the Star History website, we can see that the community’s interest in Deno has steadily increased over the past two years. Since its launch a little more than a month ago, Deno has reached 50K + Star numbers, which means that Deno is at least in the top 70 of Github’s global rankings.

Up to now, the number of two-year old Deno contributors has reached 270+ bits, with 3K + commit, 416/1920 issues and 42/3273 PR solutions (2020-05-12). At the same time, nodes that are nearly 10 years old have 2690+ contributors, 30K + commit, 977/11585 issues resolution ratio, and 316/21192 PR resolution ratio.

The following chart shows Deno’s current Star History trend.

A bet on Deno?

Everyone has their own reasons for why they study Deno. There is an interesting sound in the community that learning Deno is a “bet” that learning Deno will lead to a complete abandonment of Node and better programming opportunities in the future.

In fact, Deno is still in its early stages, and the success of Node.js is a contextual choice that cannot be replicated. So it’s too early to bet all your learning on Deno.

So what about Deno? Deno was born under the “gift culture” environment of the open source community. We see Deno as a new life to join the family, and we can learn from the process of the whole Web field to build Deno together. It is the best state to treat this “gift” at this stage.

From Node to Deno, there are a lot of positive contributions from Chinese developers.

Just for fun

The latest Node.js Developer 2020 Report, launched by Ecma members and led by alibaba, Tencent and others, points out that the younger students are, the more they pay attention to Deno. So, here’s a quote from @Kevinkassimo, a young Chinese intern at Google and one of Deno’s core contributors: Why study Deno?

To be fair, my primary reason for getting involved was “I’ve been using Node all my life but I don’t really know how it works”, so when I first saw Deno I thought “A better way to understand how Node works is to build a new Node”. – @ kevinkassimo

That’s what’s important to me about Deno. When I first entered the campus, It was the hottest moment of Node.js. I chose the front-end field because of my love for Node.js. In the following years, I also participated in and held many front-end related activities, but my understanding of Node.js has not been better broken due to my limited identity.

In the year since graduation, Node.js has developed into a very large ecosystem, where we can find a large number of NPM libraries to solve our programming needs — which also shows that we are more and more familiar with Node.js. Now that Deno is new, IN order to better understand Deno, including understanding Node.js, but also to keep up with the development of the Web as a whole, I started my journey to Deno.

At the same time, there’s a bigger mindset like the title of Linux creator Linus Torvalds’ autobiography, “Just for fun.” It all starts with something fun, something early, something that’s “Uncharted,” outside the various front-end businesses I handle at work.

So: you, why Deno?

Multiple ways to install Deno on MacOS

In addition to Windows, the most common operating system, Linux and MacOS environments also make up a significant portion of the developer community. There are solutions for installing Deno on different platforms. This section and all subsequent chapters will learn Deno on MacOS by default. In the future, the Deno Web App may be deployed on a Linux cloud server.

So if your operating system is MacOS, it’s easy to learn from this article. If your local environment is Linux or Windows, there are some differences in package managers, installation directories, and the way environment variables are configured, which shouldn’t stop you from learning more about Deno. You can search and discuss other Deno installation methods in the Issues section of Deno official, Deno community, or Deno Delving series repository, depending on your operating system.

What do I need to know about installing a package from the command line? Of course, it depends on 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…… From this point of view, the following installation methods will select denO-V to verify whether the installation is successful.

This section focuses on the installation process, and more in-depth installation principles will be covered in the future, so get started!

Installation method 1: Use curl to install the device

Curl is used to transfer data on the command line or in scripts. In this case, the first installation method is to download the deno.zip package from the remote installation script install.sh to the local directory and execute it immediately, as follows:

$ curl -fsSL https://deno.land/x/install/install.sh | sh
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # - # # # O# - 100.0% # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # (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
Copy the code

At this point the installation is half complete. According to the terminal logs after the installation, Deno is successfully installed in the user’s ~/. Deno directory. In this directory, only the binary software ~/. Deno /bin/deno is left. If you enter deno -v, the deno command will not run successfully. You need to manually configure environment variables to let the terminal know where to run the deno command.

Note: ${USER_NAME} is the user name of your operating system.

As prompted, run the following command and enter deno -v. The deno command is 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:/...
Copy the code

The Deno version installed here is 1.0.0-rc2, and the latest version as of 2020-05-13 morning is 1.0.0-RC3. The command to update the Deno version is as follows.

$ deno upgrade
# Checking for latest version
# Version has been found
# DBUA: dBUA 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/...
Copy the code

Installation method 2: Install from Homebrew

If you have already installed Deno using curl and now want to try Homebrew, you can manually uninstall Deno based on the known Deno directory and environment variable values. Ensure that the relevant directory (~ /. Deno) and related environment variable (export – p | grep deno to acceptance) were empty.

# to install Homebrew
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Copy the code

Now let’s install Deno using Homebrew, one of the best-known package managers on MacOS. Since Homebrew automatically checks for updates every time it is executed by default, the extremely slow Updating Homebrew… We will need to temporarily shut down Homebrew automatic updates before we officially install 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.4 MB
# ==> `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
Copy the code

From above terminal log and formulae. The brew. Sh/formula/den… The latest version of Deno on Homebrew does not support denO-V1.0.0-RCX, only 0.42.0. Homebrew places the Deno software under /usr/local/deno and automatically updates the environment variables in /usr/local/bin.

$ 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
Copy the code

Installation mode 3: Install from the ASDF

ASDF is an extensible version manager that supports Ruby, Node.js, Elixir, Erlang, etc. We can use ASDF to install Deno, including fast management of Deno versions. First install the ASDF, either through Git and manually configuring the environment variables, or 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.6 KB, built in 18 seconds
Copy the code

Before installing the Deno, configure the ASDF address for the Deno. ASDF can easily implement Deno multi-version control.

$ 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
Copy the code

You can see that Deno has been successfully installed through ASDF, but you need to create a soft link, that is, 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
Configure the Deno version globally$ASdf global deno 1.0.0-rc3Set Deno version in current directory
$ asdf localDeno 1.0.0 -rc3View all available Deno versions
$ asdf list all deno
View the current Deno version
$ asdf current deno # 1.0.0-rc3 (set by /Users/${USER_NAME}/. Tool -versions)
Copy the code

Installation method 4: Install from the source code

Due to space constraints, there is a lot of knowledge that can be derived from installing the source code, which will not be covered in this article, and will be updated in the future.

What installation method should I choose?

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

Deno’s simple actual combat

Prepare a Hello World program

Brian Kernighan wrote a programming book called THE C Programming Language in 1978, in which the Hello World program was first referenced, and the tradition continues to this day. Here, the first program about Deno can also start with Hello World.

Because Deno has a built-in TypeScript runtime, the example here is welcome.ts available on the official website, as shown below.

// welcome.ts
// Import the server.ts module from the URL and extract (ES6 destruct 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 address of the port that the program is listening for on the terminal
console.log("http://localhost:8000/");
// Return "Hello World" when accessing the listening port using ES9's new for await syntax
for await (const req of s) {
  req.respond({ body: "Hello World\n" });
}
Copy the code

If the preceding welcome.ts succeeds in running directly in Deno, what does it mean? In just a few lines of code, Deno itself provides an official standard library (which eliminates the cost of finding and comparing third-party libraries), Deno modules can be imported directly from the URL (a unique way to import), Deno supports the latest ES standard (without having to configure various transferers for ES6+ syntax), Deno has a built-in TypeScript runtime (no need to manually install and configure the TypeScript migrator).

Hello World

Now execute welcome.ts. Since the remote server.ts file has been imported into the code, deno will now uniformly download to the global directory and execute the file.

$ 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
Copy the code

When localhost:8000 is opened, a message is displayed indicating success.

More actual combat of Deno

Future updates will continue in the Deno Delve into the open source ebook repository.

The resources

  • Deno Runtime Tutorial: Alternatives to Node.js
  • star-history.t9t.io/
  • magi.com
  • The Wolf Book: The Greater Node.js
  • deno-1-0-what-you-need-to-know
  • gitstar-ranking.com/
  • Node.js Developers annual Report 2020
  • The origin and history of the Hello World program
  • curl.haxx.se/

Subscribe & to be continued

This article belongs to the foundation of Deno Research series. In the future, we plan to gradually expand the added chapters and fill in more articles, such as:

  • Basic: step by step to learn Deno basic knowledge;
  • Node: First easy after difficult to complement the knowledge of Node, explore the difference and difference with Deno;
  • Learn more about Rust at the bottom of Deno;
  • Front end: Explore the way Deno Web front-end application development;
  • Back end: Explore the way Deno Web backend application development;
  • Architecture: Read V8 at the bottom of Deno and learn architecture.

Welcome to subscribe, grow together, please Star, Watch & Issue open source repository “Deno study”! Three in a row.

  • Github.com/hylerrix/de…
  • Github.com/hylerrix/de…
  • Github.com/hylerrix/de…