Cause of birth
Ryan Dahl (Ry), the author of Node.js, chose to leave Node.js to develop deno because he felt there were serious design flaws in Node.js, and the large number of users made it very difficult for Node.js to undergo major modifications.
Release time
In May 2009, Node.js was released. Eleven years later, Deno released version 1.0 on May 13, 2020. The official release of version 1.0 attracted a lot of attention in the IT world.
- Node.js star on Github so far:
- Deno’s Star on Github:
As you can see, deno is growing rapidly, although it would take a long time for a new thing to completely surpass or overwrite an old one, or perhaps not very likely. But the author has certain confidence in the popularity of __Deno __.
In the future, Deno and NodeJS will go hand in hand at the back end of the JS language just as Vue and React did at the front end.
The installation
- Windows installation using PowerShell:
iwr https://deno.land/x/install/install.ps1 -useb | iex
Copy the code
- MAC installation:
$ curl -fsSL https://deno.land/x/install/install.sh | sh
Copy the code
- Using Choco install:
choco install deno
Copy the code
- View the deno version
$ deno --version
Copy the code
Install the VSCode plug-in for Deno
Deno’s standard module system is based on ES, the form of import module using import url, and Deno global objects are not supported by VSCode. Therefore, Deno needs to be Deprecated to support it. And set deno.enabled to true in Settings.
The denO environment variable may not exist, so you need to configure the denO environment variable.
- Before the installation:
- After the installation:
Helloworld
- Create a new js file or ts file:
console.log('hello world');
Copy the code
Run:
deno run hellowWorld.ts # hello world
Copy the code
The characteristics of Deno
- TypeScript is built in, which is much better than Node.js only supports JS. If you want to write TS, you need to use translation.
- Standard module system based on ES.
- Simplified installation.
- Both runtime and package manager.
- The safety performance is greatly improved.
Deno built-in API usage
const dir = Deno.readDirSync(Deno.cwd());
for (const file of dir) {
console.log(file);
};
Copy the code
Run:
$ deno run --allow-read dir.ts
Copy the code
Deno supports TS by default
// index.ts
let num:number = 123;
num = 'deno';
Copy the code
Run:
deno run index.ts
Copy the code
Result: An error similar to the following is displayed
Type 'deno' is not assignable to type 'number'.
Copy the code
Deno running permission Settings
By default, Deno does not have network, file read, file write, environment variable read and other permissions, so if you want to run the use of the following can be added:
-
-a, –allow-all Allows all permissions.
-
–allow-env Allows the environment to obtain and set permissions for the environment.
-
Allow-hrtime Allows high precision timer.
-
–allow-net Indicates the permission to access the network.
-
–allow-plugin Allows plug-in permissions to be loaded.
-
–allow-read Specifies the permission to read files.
-
–allow-write Specifies the permission to write files.
-
–allow-run Allows subprocesses to run. Use the subprocess with caution because it does not have the same security as the denO process.
Reference documentation
Deno Chinese manual Deno documentation
Because it is only the first attempt, I will only write here for the time being. There will be more in-depth research or systematic summary later, looking forward to better development of denO.