The JS runtimes
Published in

The JS runtimes

10 quick one-liners in Deno

This article covers 10 randomly chosen one-liners in Deno. Let’s get started.

1

HTTP Hello world server:

Unless explicitly provided, the serve API starts a server on port 8000. The serve API (comes from standard library) is the recommended way to write HTTP servers in Deno.

2

Make a fetch request with timeout:

An exception with name TimeoutError will be raised after 1000ms.

3

Decompress gzipped body received in an HTTP request or HTTP response:

The decompressed data will be returned as a ReadableStream that can be redirected to a file or read to completion.

4

Append query parameters (URLSearchParams) to the fetch URL:

5

Test a URL against a pattern:

The output is true if match occurs, false otherwise.

6

Get number of CPUs present on the system:

The returned number of CPUs (logical) can be used to spawn the right number of workers.

7

Run a shell command and collect the output as a string:

If binary output is required, the TextDecoder part can be omitted.

8

Get value of an environment variable:

A string is returned that contains the value of the environment variable, NULL is returned if the environment variable doesn’t exist.

9

A simple static file server:

Deno provides a built-in readable stream for any open file. This readable stream can be directly given to the Response object.

10

Read a text file:

The read file is returned as a string.

Looking for more? The second part of the one-liner series is here:

This story is a part of the exclusive medium publication on Deno: Deno World.

--

--

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