Deepak Ranolia
4 min readMay 16, 2020

Deno 1.0 for Building Server-Applications in TypeScript, a superset of JavaScript

Deno is a runtime for JavaScript and Typescript that is based on the V8 JavaScript engine, Rust and Tokio. It supports Linux, macOS, Microsoft Windows as an operating systems. It was created by Ryan Dahl, creator of Node.js. In JSConf EU 2018, he announced about Deno during his talk “10 Things I Regret About Node.js”. Apart from this, stable release i.e. Deno 1.0 released on May 13, 2020.

Flatbuffers was adopted for faster, “zero-copy” serialization and deserialization but later in August 2019, FlatBuffers were finally removed

Note: JavaScript is the natural choice for dynamic language tooling; whether in a browser environment or as standalone processes

Developers can contribute on https://github.com/denoland/deno

Website deno.land/ under MIT license

Overview

Deno provides Powerful scripting environment that can address a wide range of problem domains. It is a single executable file with built-in utilities like a dependency inspector (deno info), unit testing, code formatting, and linting to improve developer experience. It uses a secure sandbox by default for execution of code. It supports Typescript without additional tooling as it is not the case with Node JS. Also, it provide type information to developers. It can be used to create web servers, perform scientific computations, etc.

Why a new deno 1.0 and not node.js versioning

Node.js uses eventEmmiter as JavaScript had no concept of Promises or async/await at the time when node.js was designed back in 2009. On the other hand, eventEmmiter does not had that kind of comfort in the working environment or it was not designed for efficiency. Due to this, many Node programs can be flooded with data. To eliminate this, pause() method was added but it requires extra code. In Deno, sockets are still asynchronous, but receiving new data requires users to explicitly read(). Deno uses bindings and are called “ops”. All callbacks in Deno in some form or another arise from promises. Rust has its own promise-like abstraction, called Futures. Through the “op” abstraction, Deno makes it easy to bind Rust future-based APIs into JavaScript promises. Also, Due to the large number of users that Node has, it is difficult and slow to evolve the system

Comparison Deno vs Node.js

  • Deno does not use npm. It uses modules referenced as URLs or file paths
  • Deno does not use package.json in its module resolution algorithm.
  • All async actions in Deno return a promise. Thus Deno provides different APIs than Node.
  • Deno requires explicit permissions for file, network, and environment access.
  • Deno always dies on uncaught errors.
  • Uses "ES Modules" and does not support require(). Third party modules are imported via URLs:

import * as log from "https://deno.land/std/log/mod.ts";

Example

The following Deno script implements a basic HTTP server:

import { serve } from
"https://deno.land/std@v0.50.0/http/server.ts";
for await (const req of serve({
port: 8000
})) {
req.respond({
body: "Hello World\n"
})
}

The following runs a basic Deno script (sandbox mode):

deno run main.ts

Explicit flags are required to expose corresponding permission:

deno run --allow-read --allow-net main.ts

Following is an example to restrict file system access by whitelist.

$ deno run — allow-read=/usr https://deno.land/std/examples/cat.ts /etc/passwderror: Uncaught PermissionDenied: read access to “/etc/passwd”, run again with the — allow-read flag► $deno$/dispatch_json.ts:40:11 at DenoError ($deno$/errors.ts:20:5)

Inspect the dependency tree of the script:

deno info main.ts

A basic hello-world program in Deno looks like the following (as in Node.js as well on client-side):

console.log("Hello world");

Is deno the change we want in IT industry?

As we know through the survey conducted on different platforms that more than 50% of the developer roles are full stack developers followed by the back-end developers and front-end developer’s. JavaScript is the most commonly used programming language among developer’s. Also, Four web most popular framework like Angular, React, Vue.js and jQuery uses Typescript and JavaScript as the core structure of there modules except the jQuery as it only use the JavaScript. Node.js is now a decade old language for creating server-applications. Deno 1.0 is the second language for creating server — applications however deno uses typescript by default and it provide the typescript environment for developers. In the next coming years, node.js applications will run in deno environment as well.

As a technical expert, it was quite hectic to find the latest node.js tutorials in open source community and you end up in watching, reading the old version of node.js tutorials, blogs, codes etc. and when it comes to coding in node.js, i really hate JS file and the environment i have to work as its pretty old. Deno 1.0 provides that platform and ease of programming. Also, If a front-end developers has expertise on typescript, deno is perfect platform for them to chose over node.js.

In addition, deno 1.0 is here and in the future releases team will be focused on improving the system like TSC bottleneck, plugins/extensions, HTTP server performance and compatibility. In last, Deno 1.0 is a proper asynchronous server and a hello-world Deno HTTP server does about 25k req/sec with a max latency of 1.3 ms. (If it’s not, probably JavaScript is not the best choice which works on different platforms.)

Stay Tuned ;)

Deepak Ranolia
Deepak Ranolia

Written by Deepak Ranolia

Strong technical skills, such as Coding, Software Engineering, Product Management & Finance. Talk about finance, technology & life https://rb.gy/9tod91

No responses yet