The creator of Node js found there were many flaws in Node as can be shown in this video: https://www.youtube.com/watch?v=M3BM9TB-8yA.
He started the project called deno 2 yrs back which was open source and was in alpha. Recently deno 1.0 (production-ready) was released on May 13, 2020.
- Full typescript support, natively compiled. Hence you can take advantage of features like IntelliSense.
- Extensive standard library.
- It has the standard ES modules compatibility.
- No package manager, modules are imported via URL.
- First-class await support.
- Built-in testing functionality.
- Browser compatible whereas Node was just for the backend. ( classes like window can be accessed )
Will it replace Node js?
No, Node is now a well-established technology and it is being used extensively worldwide. But people will start to move towards deno as it is essentially Node but better.
Similarities between Node and deno
- Both are developed upon the V8 chromium engine.
- Node is written with c++and js while deno is made with rust and typescript.
- Node has a package manager called npm while in deno you import ES modules from URLs.
- Node uses CommonJS syntax while deno uses official ES modules syntax.
- Deno uses Ecmascript features in APIs and libraries while Node uses callbacks.
- Deno has great security features while Node allows access to anything.
- Deno is trying to be compiled in a binary. ( but this isn’t a production-ready feature )
Node was implemented before JS had Promises or async / await. Node’s counterpart to promises was the EventEmitter, which APIs in Node are based upon.
While All callbacks in Deno arise from promises.
The Deno Sandbox
Deno creates a sandbox environment that only allows system calls that are allowed explicitly by its CLI.
There is nothing stopping Node from accessing your private files on disk and sending it to the server while Deno tries to replicate the same permission model that the browser implements.
If a program needs to access the network we have to give it the permission explicitly like this:
deno run --allow-net app.ts
First Class typescript support
Deno supports TypeScript without additional tooling. The runtime is designed with TypeScript in mind. The deno types command provides type declarations for everything provided by Deno. Deno’s standard modules are all written in TypeScript.
Deno is not compatible with existing JS tooling and Node packages. But efforts are being done to make the tooling more compatible.
You can easily format the code based on standards for easy readability by
Deno fmt app.ts
Should you learn Deno?
Node will be used extensively in the industry. So the first step should always be to learn Node and then deno for the new clients trying to implement it.
The Standard library
- Archive : tar archive utilities.
- Async : async utilities.
- Bytes : helpers to manipulate bytes slices.
- Log : logging utilities.
- Mime : support for multipart data.
- Datetime: date/time parsing.
- Encoding : encoding/decoding for various formats.
- Flags : parse command-line flags.
- Fmt : formatting and printing.
- Node : Node.js compatibility layer.
- Path : path manipulation.
- Ws : WebSockets.
- Fs : file system API.
- Hash : crypto lib.
- Http : HTTP server.
- Io : I/O lib.
Let’s get our hands dirty with deno:
Using Shell (macOS, Linux): $ curl -fsSL https://deno.land/x/install/install.sh | sh Using PowerShell (Windows): $ iwr https://deno.land/x/install/install.ps1 -useb | iex Using Homebrew (macOS): $ brew install deno Using Chocolatey (Windows): $ choco install deno Using Scoop (Windows): $ scoop install deno
Try running a simple program:
$ deno run https://deno.land/std/examples/welcome.ts
Or a more complex one:
You can use this command to get the manual for deno CLI
$ deno –help: