Introduction

This article is a long overdue update to one of the initial articles here. It’s been more than a year since the hello world comparison was done (right after Deno v1.0 was released). The article was updated two times to keep up with the latest releases of Deno & Node. In Deno world, things have changed significantly since the last update. There is a new, stable & performant native HTTP server in Deno. It’s the perfect time to take a fresh look at the performance comparison.

Configuration

Environment

The performance comparison is executed on the following environment:

  • System: MacBook with Intel Core…

Introduction

HTTP server is the bread and butter of runtimes like Deno, Node.js, etc. Initially, Deno’s HTTP server was mostly a part of the standard library. Due to this, a large part of the implementation of the HTTP server was in TypeScript. The performance was good, but there was a tremendous scope for improvement.

To make it more efficient, Deno enhanced by using Rust’s hyper HTTP server and moved all the HTTP server code into the core runtime. Recently, Deno has made a stable release of the native HTTP server (hyper based). …


This article is a part of the Deno nuggets series, where each article attempts to suggest a pointed solution to a specific question that can be read in less than a minute. There is no ordering of nuggets.

Problem

How to read/write binary files in Deno?

> ls -l sample.png 
23182 Apr 3 22:02 sample.png

How to read/write text files in Deno?

> ls -l sample.txt 
22 Sep 15 09:59 sample.txt

How to read/write JSON files in Deno?

> ls -l sample.json 
72 Sep 21 09:28 sample.json

Solution

Imports

No imports are required.

Binary files

Any binary file can be read using Deno.readFile (sync variant…


This article is a part of the Deno nuggets series, where each article attempts to suggest a pointed solution to a specific question that can be read in less than a minute. There is no ordering of nuggets.

Problem

How to use in-memory KV database in Deno?

set an item ('key', 'value');
get an item ('key');
remove an item ('key');

Solution

Imports

No imports are required.

Session Storage

Deno comes bundled with web’s standard in-memory global database called sessionStorage. This is the same data storage that’s available in browsers. This database stays in memory for the duration of the Deno application. Internally, sessionStorage is implemented…


Introduction

This article is a long overdue update to one of the initial articles here. It’s been more than a year since the hello world comparison was done (right after Deno v1.0 was released). The article was updated two times to keep up with the latest releases of Deno & Node. In Deno world, things have changed significantly since the last update. There is a new, stable & performant native HTTP server in Deno. It’s the perfect time to take a fresh look at the performance comparison.

Configuration

Environment

The performance comparison is executed on the following environment:

  • System: MacBook with Intel Core…


This article is a part of the Deno nuggets series, where each article attempts to suggest a pointed solution to a specific question that can be read in less than a minute. There is no ordering of nuggets.

Problem

How to redirect a request in Deno?

> curl http://localhost:5000 -L
HTTP/1.1 302 Found
location: http://localhost:5000/versions/v5
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (127.0.0.1) port 5000 (#0)
GET /versions/v5 HTTP/1.1
HTTP/1.1 200 OK
This is version v5

Solution

Imports

No imports required.

Redirection

The HTTP request can be redirected easily by using the standard Response object’s redirect function call. The…


This article is a part of the Deno nuggets series, where each article attempts to suggest a pointed solution to a specific question that can be read in less than a minute. There is no ordering of nuggets.

Problem

How to use callback style with native HTTP server in Deno?

HTTP server(listenAddress, callbackHandler => {});

To read more about native HTTP server in Deno, visit the article here.

Solution

Imports

To write an HTTP server using callback style, a function called listenAndServe needs to be imported from Deno’s standard library’s HTTP module:

import {listenAndServe} from "https://deno.land/std/http/mod.ts";

HTTP server

The callback style HTTP server can be…


This article is a part of the Deno nuggets series, where each article attempts to suggest a pointed solution to a specific question that can be read in less than a minute. There is no ordering of nuggets.

Problem

How to process a file line-by-line?

> deno run --allow-read processFile.ts 
Processing: Learning
Processing: Deno
Processing: Is
Processing: Fun!

Solution

Imports

To get lines from a Reader, readLines function need to be imported from Deno’s standard library’s io module:

import {readLines} from "https://deno.land/std/io/bufio.ts";

Reading line-by-line

There are just two steps in reading a file line-by-line:

  • Step 1: Open the file (Deno.open) …


This article is a part of the Deno nuggets series, where each article attempts to suggest a pointed solution to a specific question that can be read in less than a minute. There is no ordering of nuggets.

Problem

How to write an echo server over WebSocket?

> deno run --allow-all echo_client.ts
>>> 7a648426-5681-4f12-8b91-80f4068d90d2
<<< 7a648426-5681-4f12-8b91-80f4068d90d2
>>> 904b11d8-1dc5-441b-a011-6b6725776b41
<<< 904b11d8-1dc5-441b-a011-6b6725776b41
>>> 14986686-b002-4523-b882-8b83bc97805b
<<< 14986686-b002-4523-b882-8b83bc97805b
>>> 87969a7a-f370-467e-b748-0fda2306d426
<<< 87969a7a-f370-467e-b748-0fda2306d426

Solution

Imports

No imports are required.

Echo server & client

Server

The echo sever takes the following steps:

  • Create a TCP server (listen)
  • Serve HTTP over an incoming TCP connection (serveHttp)
  • Upgrade HTTP connection to WebSocket
  • At the very…


This article is a part of the Deno nuggets series, where each article attempts to suggest a pointed solution to a specific question that can be read in less than a minute. There is no ordering of nuggets.

Problem

How to run shell commands from Deno?

> cat someScript.sh
echo "Hello world to $1"
echo "Hello world to $2" >&2

The shell script someScript.sh logs first argument to stdout and second argument to stderr.

Solution

Imports

No imports are required.

Run a shell command

Here are the steps involved in running a shell command and optionally collecting the output/error:

  • Use Deno.run to create a child process (pass…

Mayank Choubey

Deno, Node.js, etc.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store